for (int j = 0; j x; j++) {
System.out.print(matrix[i][j] + " ");
//这里用System.out.print()
//System.out.println()输出玩内容后会换行
}
所谓的二维数组其实是数组的数组(每个一维数组的长度可以不同,所以二维数组也称为锯齿数组).假设有:
arr[0].length表示第1个一维数组的长度1,即1列.
所以,这个二维数组看起来像这个样子:
它每一行的长度都不同.
import java.util.Arrays;
public class AAA
{
public static void main(String[] args)
};
//两种遍历方法
//第一种
/*for(int i=0;ia.length;i++){
int[] b =a[i];
for (int j=0;jb.length;j++ ){
System.out.print(b[j]+" ");
System.out.println();
}*/
//第二种
for(int i = 0;i a.length;i++){
String s = Arrays.toString(a[i]);
System.out.println(s);
public class Test { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[][] a=new int[row][row];
a[0][0]=1;
for(int i=1;irow;i++){
a[zero++][change]=value++;
continue;
a[j][j]=value++;
a[change][--zero]=value++;
}else{
a[change][zero++]=value++;
a[--zero][change]=value++;
n++;
change++;
zero=0;
String out="";
for(int i=0;irow;i++){
for(int j=0;jrow;j++){
out=""+a[i][j];
if(out.length()==1)
out="0"+out;
System.out.print(out+" ");
}}
运行测试通过
以上就是土嘎嘎小编为大家整理的二维数组输出代码java相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!