
java编写程序 4. 编写程序,从键盘输入学生成绩,根据成绩判断:如果成绩小于60,则输出“不及格”;若成
编写程序,从键盘输入学生成绩,根据成绩判断:如果成绩小于60,则输出“不及格”;若成绩在60和75之间,应输出“及格”;若成绩在75和90之间,应输出“良”;若成绩大于9...
编写程序,从键盘输入学生成绩,根据成绩判断:如果成绩小于60,则输出“不及格”;若成绩在60和75之间,应输出“及格”;若成绩在75和90之间,应输出“良”;若成绩大于90,应输出“优”。如果输入的成绩超出0~100的范围,则输出“成绩无效”。
展开
推荐于2018-02-28
展开全部
public static void main(String[] args) throws Exception {
System.out.print("请输入成绩:");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
try {
int score = Integer.parseInt(str);
if (score >= 0 && score < 60){
System.out.println("不及格");
} else if (score >= 60 && score < 75){
System.out.println("及格");
} else if (score >= 75 && score < 90) {
System.out.println("良");
} else if (score >= 90 && score <= 100){
System.out.println("优");
} else {
System.out.println("成绩无效");
}
} catch (NumberFormatException e){
System.out.println("成绩输入错误");
}
}
代码还是自己敲的好
展开全部
public static void main(String[] args) throws Exception {
System.out.print("请输入成绩:");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
try {
int score = Integer.parseInt(str);
if (score >= 0 && score < 60){
System.out.println("不及格");
} else if (score >= 60 && score < 75){
System.out.println("及格");
} else if (score >= 75 && score < 90) {
System.out.println("良");
} else if (score >= 90 && score <= 100){
System.out.println("优");
} else {
System.out.println("成绩无效");
}
} catch (NumberFormatException e){
System.out.println("成绩输入错误");
}
}
System.out.print("请输入成绩:");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
try {
int score = Integer.parseInt(str);
if (score >= 0 && score < 60){
System.out.println("不及格");
} else if (score >= 60 && score < 75){
System.out.println("及格");
} else if (score >= 75 && score < 90) {
System.out.println("良");
} else if (score >= 90 && score <= 100){
System.out.println("优");
} else {
System.out.println("成绩无效");
}
} catch (NumberFormatException e){
System.out.println("成绩输入错误");
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.util.Scanner;
public class ScoreJudge {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double score = 0;
try {
System.out.print("请输入成绩:");
score = sc.nextDouble();
} catch (NumberFormatException nbFmtExp) {
System.out.println("成绩输入错误");
return;
}
if (score < 0 || score > 100) {
System.out.println("成绩无效");
}
if (score >= 0) {
if (score < 60) {
System.out.println("不及格");
} else if (score < 75) {
System.out.println("及格");
} else if (score < 90) {
System.out.println("良");
} else if (score <= 100) {
System.out.println("优");
}
}
}
}
public class ScoreJudge {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double score = 0;
try {
System.out.print("请输入成绩:");
score = sc.nextDouble();
} catch (NumberFormatException nbFmtExp) {
System.out.println("成绩输入错误");
return;
}
if (score < 0 || score > 100) {
System.out.println("成绩无效");
}
if (score >= 0) {
if (score < 60) {
System.out.println("不及格");
} else if (score < 75) {
System.out.println("及格");
} else if (score < 90) {
System.out.println("良");
} else if (score <= 100) {
System.out.println("优");
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询