您现在的位置是:首页 > 文章详情

Java——小程序练习一

日期:2019-07-14点击:323

编写程序:由键盘输入给出一个百分制成绩,要求输出成绩等级’A’、’B’、’C’和’D’,90分以上为’A’,75~89为’B’,60~74为’C’,60分以下为’D’。

最开始写的方法:没有注意到百分制的限定,缺少条件分析,思考不到位。

public class Test01 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int score = scanner.nextInt();
if (score>=90) {
System.out.println("A");
}else if (score>=75 && score<=89) {
System.out.println("B");
}else if (score>=60 && score<=74) {
System.out.println("C");
}else if (score<60) {
System.out.println("D");
}
}
}

改正后:

public class Test01 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int score = scanner.nextInt();
if (score>=90&&score<=100) {
System.out.println("A");
}else if (score>=75 && score<=89) {
System.out.println("B");
}else if (score>=60 && score<=74) {
System.out.println("C");
}else if (score<60&&score>=0) {
System.out.println("D");
}else{
System.out.println("很显然,这成绩是假滴!");
}
}
}

原文链接:https://yq.aliyun.com/articles/709034
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章