第一行 总的课程数n(n<10); 第二行 相应课程的学分(两个学分间用空格隔开); 第三行 对应课程的实际得分; 此处输入的所有数字均为整数。
输出有一行,总评绩点,精确到小数点后2位小数。(printf("%.2f",GPA);)
5 4 3 4 2 3 91 88 72 69 56
2.52
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] credits = new int[n]; int[] scores = new int[n]; for (int i = 0; i < n; i++) { credits[i] = in.nextInt(); } for (int j = 0; j < n; j++) { scores[j] = in.nextInt(); } double result = 0; double sum=0; for (int k = 0; k < n; k++) { result =result+mapping(scores[k])*credits[k]; sum=sum+credits[k]; } System.out.println(String.format("%.2f",result/sum)); } public static double mapping(int n) { if(n >= 90 && n <= 100) { return 4.0; } else if(n >= 85 && n <= 89) { return 3.7; } else if(n >= 82 && n <= 84) { return 3.3; } else if(n >= 78 && n <= 81) { return 3.0; } else if(n >= 75 && n <= 77) { return 2.7; } else if(n >= 72 && n <= 74) { return 2.3; } else if(n >= 68 && n <= 71) { return 2.0; } else if(n >= 64 && n <= 67) { return 1.5; } else if(n >= 60 && n <= 63) { return 1.0; } else { return 0.0; } } }
import java.text.DecimalFormat; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] credit = new int[n]; int[] score = new int[n]; // 总的学分 int credits=0; for (int i = 0; i < n; i++){ credit[i]=scanner.nextInt(); credits+= credit[i]; } for (int i = 0; i < n; i++) score[i]= scanner.nextInt(); double average =0; for (int i = 0; i < n; i++) average+= scoreToGPA(score[i])*credit[i]; DecimalFormat df = new DecimalFormat(".00"); System.out.println(df.format(average/credits)); } /** * 90——100 4.0 85——89 3.7 82——84 3.3 78——81 3.0 75——77 2.7 72——74 2.3 68——71 2.0 64——67 1.5 60——63 1.0 60以下 0 * */ static double scoreToGPA(int score){ if (score>=90) return 4.0; else if (score>=85) return 3.7; else if (score>=82) return 3.3; else if (score>=78) return 3.0; else if (score>=75) return 2.7; else if (score>=72) return 2.3; else if (score>=68) return 2.0; else if (score>=64) return 1.5; else if (score>=60) return 1.0; else return 0.0; } }
import java.util.Scanner; public class GradePoint { public static void main(String args[]) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); int[] studyFen = new int[n]; int[] grade = new int[n]; float point = 0; int sum = 0; for (int i = 0; i < n; i++) { studyFen[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { grade[i] = sc.nextInt(); } for (int i = 0; i < grade.length; i++) { if (grade[i] >= 90 && grade[i] <= 100) { point += 4.0 * studyFen[i]; } else if (grade[i] >= 85 && grade[i] <= 89) { point += 3.7 * studyFen[i]; } else if (grade[i] >= 82 && grade[i] <= 84) { point += 3.3 * studyFen[i]; } else if (grade[i] >= 78 && grade[i] <= 81) { point += 3.0 * studyFen[i]; } else if (grade[i] >= 75 && grade[i] <= 77) { point += 2.7 * studyFen[i]; } else if (grade[i] >= 72 && grade[i] <= 74) { point += 2.3 * studyFen[i]; } else if (grade[i] >= 68 && grade[i] <= 71) { point += 2.0 * studyFen[i]; } else if (grade[i] >= 64 && grade[i] <= 67) { point += 1.5 * studyFen[i]; } else if (grade[i] >= 60 && grade[i] <= 63) { point += 1.0 * studyFen[i]; } else if (grade[i] < 60) { point += 0; } } for (int i = 0; i < studyFen.length; i++) { sum += studyFen[i]; } System.out.printf("%.2f", point / sum); } } }
import java.util.*; import java.text.DecimalFormat; public class Main { public static double helper(int score) { if (score >= 90 && score <= 100) { return 4.0; } else if (score >= 85 && score <= 89) { return 3.7; } else if (score >= 82 && score <= 84) { return 3.3; } else if (score >= 78 && score <= 81) { return 3.0; } else if (score >= 75 && score <= 77) { return 2.7; } else if (score >= 72 && score <= 74) { return 2.3; } else if (score >= 68 && score <= 71) { return 2.0; } else if (score >= 64 && score <= 67) { return 1.5; } else if (score >= 60 && score <= 63) { return 1.0; } else { return 0.0; } } public static void main(String[] args) { Scanner reader = new Scanner(System.in); int n = reader.nextInt(); int[] score = new int[n]; int[] grade = new int[n]; for (int i = 0; i < n; ++i) { grade[i] = reader.nextInt(); } int all_score = 0; double all_grade = 0.0; for (int i = 0; i < n; ++i) { score[i] = reader.nextInt(); all_grade += grade[i] * helper(score[i]); all_score += grade[i]; } DecimalFormat df=new java.text.DecimalFormat("0.00"); System.out.println(df.format(all_grade*1./all_score)); } }