在 Java 中求最高分和最低分需要以下流程:
1. 定义数组和输入成绩。2. 用循环语句和条件判断语句求最高分和最低分。3. 输出最高分和最低分。
下面是详细的代码实现:
// 定义数组和输入成绩int[] scores = new int[5]; // 定义长度为 5 的数组Scanner scanner = new Scanner(System.in);for (int i = 0; i< scores.length; i++) { // 循环输入成绩System.out.print("请输入学生" + (i + 1) + "的成绩:");scores[i] = scanner.nextInt();}// 求最高分和最低分int maxScore = scores[0];int minScore = scores[0];for (int i = 1; i< scores.length; i++) { // 从第二个成绩开始比较if (scores[i] >maxScore) { // 如果当前成绩大于最高分,则更新最高分maxScore = scores[i];}if (scores[i]< minScore) { // 如果当前成绩小于最低分,则更新最低分minScore = scores[i];}}// 输出最高分和最低分System.out.println("最高分:" + maxScore);System.out.println("最低分:" + minScore);