永发信息网

java题:要求从键盘输入0-100之间的数,并根据所处分数段的不同分“

答案:3  悬赏:10  手机版
解决时间 2021-04-03 17:25
  • 提问者网友:浮克旳回音
  • 2021-04-03 00:48
java题:要求从键盘输入0-100之间的数,并根据所处分数段的不同分“
最佳答案
  • 五星知识达人网友:酒醒三更
  • 2021-04-03 02:14
import java.util.Scanner;

public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true){
String s = sc.nextLine();
if(s.equals("#")){
System.out.println("系统退出");
System.exit(-1);
}
if(s!=null&&s.matches("^[0-9]+$")){
if(Integer.parseInt(s)<0||Integer.parseInt(s)>100){
System.out.println("你输入的数据不在有效的范围");
continue;
}else if(Integer.parseInt(s)>=90&&Integer.parseInt(s)<=100){
System.out.println("优");
continue;
}else if(Integer.parseInt(s)<90&&Integer.parseInt(s)>=80){
System.out.println("良");
continue;
}else if(Integer.parseInt(s)<80&&Integer.parseInt(s)>=70){
System.out.println("中");
continue;
}else if(Integer.parseInt(s)<70&&Integer.parseInt(s)>=60){
System.out.println("及格");
continue;
}else if(Integer.parseInt(s)<60&&Integer.parseInt(s)>=0){
System.out.println("不及格");
continue;
}
}else{
System.out.println("请输入数字");
continue;
}
}
}
}
全部回答
  • 1楼网友:第四晚心情
  • 2021-04-03 04:22
public class Test {
private void Input(){
System.out.println("输入分数");
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine()){
String str = sc.nextLine();
if(str.equals("#"))
break;
int b;
try {
b = Integer.parseInt(str);
if(b>100){
    System.out.println("你输入的数据不在有效的范围");
    continue;
}
    
} catch (Exception e) {
System.out.println("你输入的数据不在有效的范围");
continue;
}
GradeHandle(b);
}
}
private void GradeHandle(int a){
String msg;
if(a>=90)
msg = "优秀";
else if(a>=80&&a<90)
msg="良";
else if(a>=70&&a<80)
msg="中";
else if(a>=60&&a<70)
msg="及格";
else
msg="不及格";
System.out.println(msg);
}

public static void main(String[] args) {
// TODO Auto-generated method stub
Test t = new Test();
t.Input();
}
}
  • 2楼网友:冷風如刀
  • 2021-04-03 02:43
//前面做输入的东西判断; 只能为数字,和#
String num = "";
string level = "";
while(num != "#"){
if(num >100) level = "你输入的数据不在有效的范围"
else if(num >90) level = "优秀"
else if(num >80) level = "良"
else if(num >70) level = "中"
else if(num >60) level = "及格"
else if(num <60) level = "不及格"
}
println(level);
大致的意思哦。里面的判断还可以用witch case 之类的。。。。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯