不知道哪里出问题了无法遍历输出123

public class ArryTest {
public static void mian(String[] args) {
//遍历一个数组,输出元素数组的各元素值
int[][] arr = {{1, 2, 3}, {7, 3, 7}, {2, 3, 4}};

    //使用方法完成输出
    MyTools tool = new MyTools();
    //遍历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();
    //}
    tool.printArr(arr);
    tool.printArr(arr);
    tool.printArr(arr);
}

}
class MyTools{
//方法,接收一个二维数组

public void printArr(int[][] arr){
//对传入的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();
    }
}

}

public static void mian这里你拼写错了,应该是 main

img

修改后代码能正常运行

img

ArryTest

public class ArryTest {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //遍历一个数组,输出元素数组的各元素值
        int[][] arr = {{1, 2, 3}, {7, 3, 7}, {2, 3, 4}};
        //使用方法完成输出
        MyTools tool = new MyTools();
        //遍历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();
        //}
        tool.printArr(arr);
        tool.printArr(arr);
        tool.printArr(arr);
    }
}

MyTools


class MyTools {
    public void printArr(int[][] arr){
        //对传入的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();
        }
    }
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632