zoukankan      html  css  js  c++  java
  • 27.遍历二维数组

    import java.util.Scanner;
    
    /**
     * 有5个班各5名学生某门课程的成绩,计算5个班各自的总成绩
     * */
    public class FiveTotal {
        public static void main(String[] args) {
            Scanner input=new Scanner(System.in);
            int [][] array = new int[5][5]; //5个班的成绩
            //i:班级  j:各班级的学生
            for(int i=0;i<array.length;i++){
                System.out.println("**********第"+(i+1)+"个班**********");
                for(int j=0;j<array[i].length;j++){
                    System.out.print("请输入第"+(j+1)+"个学生的成绩:");
                    array[i][j]=input.nextInt();
                    
                }
            }
            System.out.println("***********成绩统计************");
            int total; //保存总成绩
            for(int i = 0; i < array.length; i++) {
                String str = (i+1) + "班";
                total = 0; //每次循环到此都将其归0
                for(int j = 0; j < array[i].length; j++) {
                    total += array[i][j]; //成绩叠加
                }
                System.out.println(str+"总成绩:" + total);
            }
        }
    }
  • 相关阅读:
    Spring源码剖析4:懒加载的单例Bean获取过程分析
    css3动画 9步
    删除文件
    监听变量的方法
    jPaginate应用
    bg-render+bg-class+filter
    css兼容处理
    系统前端关键点
    token 入门教程
    svg笔记----------path篇
  • 原文地址:https://www.cnblogs.com/xiaotaoxu/p/5536335.html
Copyright © 2011-2022 走看看