打印二位数组的程序:
class PrintArray
{
public static void main(String[] args)
{
int [][] arr= {{1,2,3},{3,5,6},{7,6,4,3}}; //定义二维数组
printArray(arr); //调用打印数组功能打印二维数组
}
public static void printArray(int [][]arr) //申明打印二维数组的功能
{
System.out.print("{"); //打印外层大括号的左边
for (int i=0;i<arr.length ; i++) //for循环嵌套
{
System.out.print("{");
for (int j=0;j<arr[i].length ;j++ )
{
if(j<arr[i].length-1)
{
System.out.print(arr[i][j]+", ");
}
else
{
System.out.print(arr[i][j]+"},");
}
}
}
System.out.println("}"); //打印外层大括号的右边
}
}
|