java优秀代码 java优雅代码( 二 )


setVisible(true);//可以让用户看到窗口
addWindowListener(new WindowAdapter() {//如果按 X, 关闭窗口
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
b.addActionListener(new ButtonListener());//添加button监听函数
}
class ButtonListener implements ActionListener {//实现click button时功能操作
public void actionPerformed(ActionEvent e) {//当click调用
if (tf1.getText()!=null) {//检查tf1 test 是否为空
try {//取异常
x = Double.parseDouble(tf1.getText());//字符转为double型
weigth = (x - 100) * 0.9;//算重量
tf2.setText("" + weigth);//显示重量
} catch (NumberFormatException ex) {
tf1.setText("");//如果输入不是数字,设为空
}
}
if (tf1.getText().equals("")==true){//tf1是否为空
y = Double.parseDouble(tf2.getText());//把tf2里的文本转为double 型 的
heigth = y / 0.9 + 100;//算身高根据重量
tf1.setText("" + heigth);}//显示身高
}
}
public static void main(String[] args) {//主函数,程序入口
new Change(); //建立类Change的对象,并调用他的构造函数Change().显示窗口
}
}
编写程序,输入一个学生成绩,给出相应等级:60~100优秀0~50不及格(java代码实现)import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入学生的分数:");
double score = input.nextDouble();
int level1,level2;
if(score=60.0score=100.0){
System.out.print("该学生成绩为优秀!");
}
else if(score=0 score60.0){
System.out.print("该学生成绩为不及格!");
}
else{
System.out.print("您输入的成绩有误!");
}
}
}
【java优秀代码 java优雅代码】java优秀代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java优雅代码、java优秀代码的信息别忘了在本站进行查找喔 。

推荐阅读