俄罗斯著名钢琴家:输入三个数,从大到小排列.

来源:百度文库 编辑:中科新闻网 时间:2024/05/02 02:50:26
输入一个数,判断被3 5整除 两个问题啊.

申请追加分数
import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Applet2 extends Applet implements ActionListener {
Label N = new Label("输入N");
TextField T = new TextField(10);
TextField Ts = new TextField(10);
Button B1 = new Button("被3整除");
Button B2 = new Button("被5整除");
public void init() {
add(N);
add(T);
add(B1);
B1.addActionListener(this);
add(B2);
B2.addActionListener(this);
add(Ts);
}

public void actionPerformed(ActionEvent e) { //事件处理方法
String s = e.getActionCommand();
int n = stringToInt(T.getText());
if (s.equals("被3整除")) {
if (n % 3 == 0) {
Ts.setText(n + "能被3整除");
} else {
Ts.setText(n + "不能被3整除");
}
} else if (s.equals("被5整除")) {
if (n % 5 == 0) {
Ts.setText(n + "能被5整除");
} else {
Ts.setText(n + "不能被5整除");
}
}
}

private static int stringToInt(String s) { //字符串转换成整形
return Integer.parseInt(s.trim());
}
}

输入一个数,判断被3 5整除
用% 取模判断