JAVA练习:一维数组的课后练习
没事做个经典题
题目如下:
package com.atguigu.exer; import java.util.Scanner; public class ArrayDemo3 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入学生人数:"); int number = scanner.nextInt(); int[] scores = new int[number]; int maxscore = 0; System.out.println("请依次输入他们的成绩:"); for(int i = 0;i < scores.length;i++){ scores[i] = scanner.nextInt(); if(maxscore < scores[i]){ maxscore = scores[i]; } } System.out.println("最高分是:" + maxscore); char level; for(int i = 0;i < scores.length;i++){ if(maxscore - scores[i] <= 10){ level = 'A'; }else if(maxscore - scores[i] <= 20){ level = 'B'; }else if(maxscore - scores[i] <= 30){ level = 'c'; }else { level = 'D'; } System.out.println("第" + (i+1) + "位学生的成绩是" + scores[i] + ",等级是" + level +"."); } } }
?