/*
自定义的思考题:
二维数组的遍历
要求:
输出的格式和输入的格式完全保持一致
*/
class Array2Test3
{
public static void main(String[] args)
{
int[][] arr = {{1,2},{3,4,5},{6,7},{8,9}};
printArray(arr);
}
public static void printArray(int[][] arr){
System.out.print("{");
for (int x =0;x < arr.length ;x++ )
{
System.out.print("{");
for (int y = 0;y < arr[x].length ;y++ )
{
if (x !=arr.length-1)
{
if (y != arr[x].length-1)
{
System.out.print(arr[x][y]+",");
}else
{
System.out.print(arr[x][y]+"},");
}
}else
{
if (y != arr[x].length-1)
{
System.out.print(arr[x][y]+",");
}else
{
System.out.print(arr[x][y]+"}}");
}
}
}
}
}
}
|
|