大小为6;并为两个数组的各元素做赋值操作。
public static void main(String[] args) {
//å®ä¹ä¸ä¸ªé¿åº¦ä¸º4çä¸ç»´æ°ç»
int[] arry1 = new int[4];
//å®ä¹ä¸ä¸ªé¿åº¦ä¸º6çäºç»´æ°ç»
int[][] arry2 = new int[1][6];
//为é¿åº¦ä¸º4çä¸ç»´æ°ç»åå ç´ èµå¼
arry1[0] = 0;
arry1[1] = 1;
arry1[2] = 2;
arry1[3] = 3;
//为é¿åº¦ä¸º6çäºç»´æ°ç»åå ç´ èµå¼
arry2[0][0] = 10;
arry2[0][1] = 15;
arry2[0][2] = 20;
arry2[0][3] = 30;
arry2[0][4] = 40;
arry2[0][5] = 60;
//è¾åºä¸ç»´æ°ç»åå ç´
System.out.print("ä¸ç»´æ°ç»:");
for (int i = 0; i < arry1.length; i++) {
System.out.print(arry1[i]+" ");
}
System.out.println();
//è¾åºäºç»´æ°ç»åå ç´
System.out.print("äºç»´æ°ç»:");
for (int i = 0; i < arry2.length; i++) {
int[] arr2 = arry2[i];
for (int j = 0; j < arr2.length; j++) {
System.out.print(arr2[j] + " ");
}
}
}
//å®ä¹ä¸ä¸ªé¿åº¦ä¸º4çä¸ç»´æ°ç»
int[] arry1 = new int[4];
//å®ä¹ä¸ä¸ªé¿åº¦ä¸º6çäºç»´æ°ç»
int[][] arry2 = new int[1][6];
//为é¿åº¦ä¸º4çä¸ç»´æ°ç»åå ç´ èµå¼
arry1[0] = 0;
arry1[1] = 1;
arry1[2] = 2;
arry1[3] = 3;
//为é¿åº¦ä¸º6çäºç»´æ°ç»åå ç´ èµå¼
arry2[0][0] = 10;
arry2[0][1] = 15;
arry2[0][2] = 20;
arry2[0][3] = 30;
arry2[0][4] = 40;
arry2[0][5] = 60;
//è¾åºä¸ç»´æ°ç»åå ç´
System.out.print("ä¸ç»´æ°ç»:");
for (int i = 0; i < arry1.length; i++) {
System.out.print(arry1[i]+" ");
}
System.out.println();
//è¾åºäºç»´æ°ç»åå ç´
System.out.print("äºç»´æ°ç»:");
for (int i = 0; i < arry2.length; i++) {
int[] arr2 = arry2[i];
for (int j = 0; j < arr2.length; j++) {
System.out.print(arr2[j] + " ");
}
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 2016-04-25
定义一个一位数组array1,数组大小为4;再定义一个二维数组array2,数组大小为6;并为两个数组的各元素做赋值操作。
代码:
{
int arrary1[4]={0},arrary2[6][6]={0};//两个整形数组
}
这样在一维数组里就都是0了,二维数组是6乘6的大小,也都为0
供参考
代码:
{
int arrary1[4]={0},arrary2[6][6]={0};//两个整形数组
}
这样在一维数组里就都是0了,二维数组是6乘6的大小,也都为0
供参考