为什么我运行错误?
来源:6-3 编程练习
weixin_慕婉清2222446
2019-08-27 01:26:23
import java.util.Scanner;
/*
这是一个成绩查询系统
*/
public class ScoreDemo{
public static void main(String[] args){
//创建键盘录入
Scanner score=new Scanner(System.in);
System.out.println("请输入一个成绩");
int score=sc.nextInt();
if(score>=85){
System.out.println("优秀!!");
}else if(score>=75 && <=84){
System.out.println("良!可以再优秀一点!");
}else if(score>=60 && <=74){
System.out.println("及格!还可以!");
}else{
System.out.println("不及格!情况不太妙!");
}
}
}
1回答
同学你好,代码的思路很棒,但是还有几个小错误:
1、键盘录入的对象应该与调用nextInt()方法的对象的同一个,具体修改如下:
2、代码结尾应该为英文分号; 具体位置如下:
3、在进行多个判断条件时,也需要添加变量名。
修改后的代码如下:
import java.util.Scanner; /* 这是一个成绩查询系统 */ public class ScoreDemo { public static void main(String[] args){ //创建键盘录入 Scanner sc=new Scanner(System.in); System.out.println("请输入一个成绩"); int score=sc.nextInt(); if(score>=85){ System.out.println("优秀!!"); }else if(score>=75 && score<=84){ System.out.println("良!可以再优秀一点!"); }else if(score>=60 && score<=74){ System.out.println("及格!还可以!"); }else{ System.out.println("不及格!情况不太妙!"); } } }
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
相似问题