zoukankan      html  css  js  c++  java
  • 二维数组

    class Demo05 
    {
        public static void main(String[] args) 
        {
            //1.二维数组定义
            int [][] arr=new int[2][3];
            //赋值
            arr[0][0]=3;
            arr[0][1]=2;
            arr[1][1]=4;
            //取值
    
            System.out.println(arr[0][0]);
            System.out.println(arr[0][1]);
            System.out.println(arr[0][2]);
            System.out.println(arr[0]);//地址
            System.out.println(arr);//地址
    
            for(int i=0;i<arr.length;i++){
                for(int j=0;j<arr[i].length;j++){
                        System.out.print(arr[i][j]+"	");
                }
                System.out.println();
            }
            //2.二维数组定义方式
            double[][] arr=new double[2][];
            arr[0]=new double[6];
            arr[1]=new double[3];
            a[0][0]=3.6;
            //遍历
            for(int i=0;i<arr.length;i++){
                for(int j=0;j<arr[i].length;j++){
                        System.out.print(arr[i][j]+"	");
                }
                System.out.println();
            }
            //3.二维数组定义方式
            int[][] arr={{4,5},{7,8,9},{1,2,3,4}};
    
            //遍历
            for(int i=0;i<arr.length;i++){
                for(int j=0;j<arr[i].length;j++){
                        System.out.print(arr[i][j]+"	");
                }
                System.out.println();
            }      
            int sum=0;
            for(int i=0;i<arr.length;i++){
                for(int j=0;j<arr[i].length;j++){
                    sum=sum+arr[i][j];
                }
            }
            System.out.println(sum);
        }
        
    
        }
    }
                    
  • 相关阅读:
    CF995A Tesla
    CF961D Pair Of Lines
    P1186 玛丽卡
    CF986B Petr and Permutations
    hdu6331 Problem M. Walking Plan
    Edison UVALive3488
    Be a Smart Raftsman SGU475
    100198H Royal Federation
    100197G Robbers
    Evil Book -- CodeChef
  • 原文地址:https://www.cnblogs.com/longmingyeyu/p/12532913.html
Copyright © 2011-2022 走看看