比如:
public class Example{
int a[][] = {{1, 2, 3}, {3, 4, 5}};
public static void main(String args[]){
int b = xy(a);
                  System.out.println("b的值为"+b);
}
int xy(int a[][]){
int sum = 0;
for(int i=0; i<2; i++)
for(int j=0; j<3; j++){
sum = sum + a[i][j];
}
return sum;
}
}

解决方案 »

  1.   


    public class Example{
        int a[][] = {{1, 2, 3}, {3, 4, 5}};
        public static void main(String args[]){
         //弄懂静态和非静态之间的关系
         //a 和  xy 都是非静态的 得new个实例才能使用
         Example example = new Example();
            int b = example.xy(example.a);
                      System.out.println("b的值为"+b);
        }
        int xy(int a[][]){ //就是这么传2维数组 但Java习惯上是这怎么写 int xy(int[][] a)等价的
            int sum = 0;
            for(int i=0; i<2; i++)
                for(int j=0; j<3; j++){
                    sum = sum + a[i][j];
            }
            return sum;
        }
    }
      

  2.   

    不知道为什么可以不提供第二维的长度,忘了~~C语言要提供for (int i = 0; i < a.length; i++)
    for (int j = 0; j < a[i].length; j++) {
      

  3.   

    这和Java中数组本质上其实是对象 有自己的一些属性比如length有关 所以不用维度长度
    而C语言中 数组是一个指针常量 指向的是一个起始地址 
      

  4.   

    package com.edu.xinzhan;public class Demo1 {

        static int a[][] = {{1, 2, 3}, {3, 4, 5}};
        public static void main(String args[]){
            int b = xy(a);
                      System.out.println("b的值为"+b);
        }
       static int xy(int a[][]){
            int sum = 0;
            for(int i=0; i<2; i++)
                for(int j=0; j<3; j++){
                    sum = sum + a[i][j];
            }
            return sum;
        }
    }
      

  5.   

    package com.edu.xinzhan;public class Demo1 {

        static int a[][] = {{1, 2, 3}, {3, 4, 5}};
        public static void main(String args[]){
         Demo1 demo=new Demo1();
            int b = demo.xy(a);
                      System.out.println("b的值为"+b);
        }
    int xy(int a[][]){
            int sum = 0;
            for(int i=0; i<2; i++)
                for(int j=0; j<3; j++){
                    sum = sum + a[i][j];
            }
            return sum;
        }
    }