黑马程序员技术交流社区

标题: 二维数组的遍历 [打印本页]

作者: lshaizj    时间: 2015-5-2 16:59
标题: 二维数组的遍历
class BianLi
{
        public static void main(String[] args)
        {
                int[][]arr = new int[][]{{8,5,0,1,3},{3,2,3,9},{10,11,4,8},{1,4,1}};
                System.out.print("[");
                for (int x = 0;x<arr.length ;x++ )
                {
                        System.out.print("[");
                        for (int y = 0;y<arr[x].length ;y++ )
                        {
                                if (y!=arr[x].length-1)
                                {
                                        System.out.print(arr[x][y]+";");
                                }
                                else
                                        System.out.print(arr[x][y]+"]");
                        }
                        if (x!=arr.length-1)

                        System.out.print(";");
                        else
                                System.out.println("]");
                }
        }
}


作者: 下一页5    时间: 2015-5-2 18:51
int[][]arr = new int[][]{{8,5,0,1,3},{3,2,3,9},{10,11,4,8},{1,4,1}};这个可以这样写?
作者: 下一页5    时间: 2015-5-2 18:54
int[][]arr = new int[][]{{8,5,0,1,3},{3,2,3,9},{10,11,4,8},{1,4,1}};
如果可以,那你把int换成char试试。我记得有次这样报错了


这样写你试下 char[][]arr = new char[][]{{'8','5','0','1','3'},{'3','2','3','9'},{'10','11','4','8'},{'1','4','1'}};
报错了
作者: lshaizj    时间: 2015-5-2 20:12
下一页5 发表于 2015-5-2 18:54
int[][]arr = new int[][]{{8,5,0,1,3},{3,2,3,9},{10,11,4,8},{1,4,1}};
如果可以,那你把int换成char试 ...

嗯嗯  谢谢,没注意到:P




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2