importjava.util.*;publicclassMain{intallscore=0;//初始化分数intcredit=0;//学分intdiffculty=0;//难度系数privatestaticScannerinput;publicstaticvoidmain(String[]args){input=...
import java.util.*;
public class Main {
int allscore = 0;//初始化分数
int credit= 0;//学分
int diffculty= 0;//难度系数
private static Scanner input;
public static void main(String[] args) {
input = new Scanner(System.in);
double sum = 0;
double avg = 0;
System.out.println("欢迎使用绩点计算程序");
System.out.println("1--继续 2--退出");
int a = input.nextInt();//输入选择的数字
if( a==1 ){
System.out.println("请输入学科的数量:");
int c = input.nextInt();//也是数组的数量
int m = c+2;
int[] scores = new int[m];
int[] credit= new int[m];
int [] diffculty = new int [m];
int [] results = new int[m];
int mtemp = 1;
scores[0]= 0;
credit[0]= 0;
diffculty[0]= 0;
results[0]= 0;
results[mtemp+1] = 0;
if(c > 0){
while(mtemp <= c) {
System.out.println("请输入第"+ mtemp +"个学科的成绩:");
scores[mtemp]= input.nextInt();
if(scores[mtemp] <= 60 && scores[mtemp] >= 0){
results[mtemp] = 0;
System.out.println("第"+mtemp+"个学科的绩点是:" + results[mtemp]);
}else if (scores[mtemp] > 60 && scores[mtemp] <= 100){
System.out.println("请输入第"+ mtemp +"个学科的学分:");
credit[mtemp] = input.nextInt();
System.out.println("请输入第"+ mtemp +"个学科的难度系数:");
diffculty[mtemp] = input.nextInt();
results[mtemp] = credit[mtemp]*(((scores[mtemp]-60)/10)+1)*diffculty[mtemp];
System.out.println("第"+mtemp+"个学科的绩点是:" + results[mtemp]);
}
mtemp++;
}
sum += results[mtemp];
avg = sum/c;
System.out.println("您的总绩点:" +sum);
System.out.println("您的平均绩点:" + avg);
}else {
System.out.println("对不起,您的输入有误!");
}//基础量的输入
}else if( a==2 ){
System.out.println("系统将退出,谢谢使用!");
}else{
System.out.println("对不起,您的输入有误!谢谢使用,再见!");
}
}
}
展开