# 陣列基礎

```int score1 = 88; int score2 = 81; int score3 = 74; ... int score10 = 93;```

`int[] scores = {88, 81, 74, 68, 78, 76, 77, 85, 95, 93};`

`int scores[] = {88, 81, 74, 68, 78, 76, 77, 85, 95, 93}; `

``````package cc.openhome;

public class Score {
public static void main(String[] args) {
int[] scores = {88, 81, 74, 68, 78, 76, 77, 85, 95, 93};
for(int i = 0; i < scores.length; i++) {
System.out.printf("學生分數：%d %n", scores[i]);
}
}
}
``````

```for(int score : scores) {     System.out.printf("學生分數：%d %n", score); } ```

`int ai[] = {88, 81, 74, 68, 78, 76, 77, 85, 95, 93};`
`int ai1[] = ai;`
`int i = ai1.length;`
`for(int j = 0; j < i; j++) {`
`    int k = ai1[j];`
`    ...`
`}`

`scores[3] = 86;`
`System.out.println(scores[3]);`

``````package cc.openhome;

public class XY {
public static void main(String[] args) {
int[][] cords = {
{1, 2, 3},
{4, 5, 6}
};
for(int x = 0; x < cords.length; x++) {
for(int y = 0; y < cords[x].length; y++) {
System.out.printf("%2d", cords[x][y]);
}
System.out.println();
}
}
}
``````

1 2 3
4 5 6

`for(int[] row : cords) {`
`    for(int value : row) {`
`        System.out.printf("%2d", value);`
`    }`
`    System.out.println();`
`}`