要求
总评成绩 = 期末成绩*0.6 + 平时成绩*0.4
输入总评成绩和平时成绩,输出期末成绩要考几分(0<=平时成绩<=40,0<=总评成绩<=100)
要求能多次运行(退出程序停止)
代码
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.print("输入你想要的成绩:");
int overallScores = scanner.nextInt(); //输入想要的总评成绩
if (overallScores > 100 || overallScores < 0) { //判断总评成绩是否有误
System.out.println("总评成绩有误,请重新");
System.out.println("------------------------");
continue;
}
System.out.print("输入你的平时成绩:");
int usualScores = scanner.nextInt(); //输入平时成绩
if (usualScores > 40 || usualScores < 0) { //判断平时成绩是否有误
System.out.println("平时成绩有误,请重新");
System.out.println("------------------------");
continue;
}
System.out.printf("你期末需要考%.1f分\n", (overallScores - usualScores) / 0.6);
System.out.println("------------------------");
}
}
}