题目:偷下懒直接用博主的图片
package com.atguigu.exer;
import java.util.Scanner;
public class ArrayDemo01 { ?? ?public static void main(String[] args) { ?? ??? ?//1.使用Scanner读取学生个数 ?? ??? ?Scanner scan = new Scanner(System.in); ?? ??? ?System.out.println("请输入学生个数:"); ?? ??? ?int number = scan.nextInt(); ?? ??? ?//2.创建数组,存储学生成绩 ?? ??? ?int[] scores = new int[number]; ?? ??? ?//3.给数组元素赋值 ?? ??? ?int maxScore = 0; ?? ??? ?System.out.println("请输入" + number + "个学生成绩"); ?? ??? ?for (int i = 0; i < scores.length; i++) { ?? ??? ??? ?scores[i] = scan.nextInt();? ? ?? ??? ??? ?if(maxScore < scores[i]) { ?? ??? ??? ??? ?maxScore = scores[i]; ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ?} ?? ??? ?char dengji; ?? ??? ?for (int i = 0; i < scores.length; i++) { ?? ??? ??? ?if(scores[i] >= maxScore - 10) { ?? ??? ??? ??? ?dengji = 'A'; ?? ??? ??? ?}else if(scores[i] >= maxScore - 20) { ?? ??? ??? ??? ?dengji = 'B'; ?? ??? ??? ?}else if(scores[i] >= maxScore - 30) { ?? ??? ??? ??? ?dengji = 'C'; ?? ??? ??? ?}else { ?? ??? ??? ??? ?dengji = 'D'; ?? ??? ??? ?} ?? ??? ??? ?System.out.println("student"+i+" score is" +scores[i]+" grade is "+ dengji); ?? ??? ?}?? ? ?? ??? ? ?? ?}
}
?//不管是做题还是工作,在没有头绪之前,都可以先试着把题目逐步分解成一个个小问题,然后分步完成每一个小问题。在这次编写的过程中忘记了几个基本数据类型和他的用法,上面的char定义字符就忘了,忘了就回过头去记。今天主要还是学会了如何遍历数组以及通过Scanner给数组赋值。明天接着冲,勇敢牛牛不怕困难,哈哈哈
|