一維陣列和二維陣列
阿新 • • 發佈:2019-02-10
一堆陣列
陣列
int 的預設值是0
Sting的預設值是null
boolean的預設型別是false
陣列一擔初始化他的長度是不可改變的
陣列的四步走:
1.宣告陣列
2.分配陣列
3.賦值
4.處理資料
陣列的格式
int[ ] scores = new int[2];
scores[0] = 90;
scores[1] = 85;
System.out.println(scores[0]);
}
}
陣列的格式 動態
int[ ] scores = new int[5];
//宣告
scores[0] = 90;
scores[1] = 85;
System.out.println(scores[5]);
//結果為0 int陣列預設型別為0
}
第二種格式 靜態
int[] scores = new int[]{90,85,70,65,55}
System.out.println(scores[4]);//輸入結果55
}
二維陣列 靜態
int arr[][]={{1,2},{3},{7,8,56}}
二維陣列 動態
int a[][]=new int[3][];
a[0]=new int[2];
a[1]=new int[4];
a[2]=new int[3];