posts - 45,comments - 0,views - 4804
复制代码
public class Demo1 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        /*System.out.println("输入学生人数:");
        int n =input.nextInt();
        int score = 0,sum =0,max = 0;
        for(int i=1;i<=n;i++){
            System.out.println("第"+i+"个学生成绩为:");
             score = input.nextInt();
            sum +=score;
            if(score>max){
                max = score;
            }
        }
        System.out.println("总成绩:" + sum);
        System.out.println("最大值:" + max);*/

        System.out.println("输入学生人数:");
        int n = input.nextInt();
        int sum = 0;
        int[] scoreArray = new int[n];
        for (int i = 0; i < n; i++) {
            System.out.println("第" + (i + 1) + "个学生成绩为:");
            int score = input.nextInt();
            scoreArray[i] = score;
            sum += score;
        }
        int max = scoreArray[0], min = scoreArray[0];
//        for (int index = 1; index < n; index++) {
//            int s = scoreArray[index];
//            max = (max>s)?max:s;
//            min = (min<s)?min:s;
//        }
        for (int s : scoreArray) {
            max = (max>s)?max:s;
            min = (min<s)?min:s;
       }

        System.out.println("总成绩:" + sum);
        System.out.println("最大值:" + max);
        System.out.println("最小值:" + min);
    }
}
复制代码

 

posted on   小贤看世界  阅读(97)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示