Professional Documents
Culture Documents
ITPF01 Week8 Array and Java GUI
ITPF01 Week8 Array and Java GUI
To declare an array in Java, define a variable type with the square brackets.
For example: Java C++
//Example Declaration with Value;
String [] student_names = {“Melgine”, “Jaze”, “Jaeden”}; string student_names[] = {“Melgine”, “Jaze”, “Jaeden”};
int [] myNum = {5, 10, 15, 20}; int myNum[] = {5, 10, 15, 20};
Example:
myList = new double[10];
arrayRefVar.length
Usage:
After an array is created, an indexed variable can be used in the same way
as a regular variable. For example, the following code adds the value in
myList[0] and myList[1] to sum.
1 2 3 4 5 6 7 8 9 10 1
2
3
1 2 3 4 5 6 7 8 9 10 2
2 4 6 8 10 12 14 16 18 20 4
6
12
1 1 2 14
16
18
Java Program with Array and Loop
1 2 3 4 5 6 7 8 9 10 3
2 4 6 8 10 12 14 16 18 20 6
3 6 9 12 15 18 21 24 27 30 9
15
18
2 2 3 21
24
27
30
Java Program with Array and Loop
1 2 3 4 5 6 7 8 9 10 4
2 4 6 8 10 12 14 16 18 20 8
3 6 9 12 15 18 21 24 27 30 12
20
3 3 4 24
28
32
36
Java Program with Array and Loop
1 2 3 4 5 6 7 8 9 10 5
2 4 6 8 10 12 14 16 18 20 10
3 6 9 12 15 18 21 24 27 30 15
25
4 4 5 30
35
40
45
Java Program with Array and Loop
1 2 3 4 5 6 7 8 9 10 6
2 4 6 8 10 12 14 16 18 20 12
3 6 9 12 15 18 21 24 27 30 18
1 2 3 4 5 6 7 8 9 10 7
2 4 6 8 10 12 14 16 18 20 14
3 6 9 12 15 18 21 24 27 30 21
1 2 3 4 5 6 7 8 9 10 8
2 4 6 8 10 12 14 16 18 20 16
3 6 9 12 15 18 21 24 27 30 24
1 2 3 4 5 6 7 8 9 10 9
2 4 6 8 10 12 14 16 18 20 18
3 6 9 12 15 18 21 24 27 30 27
1 2 3 4 5 6 7 8 9 10 10
2 4 6 8 10 12 14 16 18 20 20
3 6 9 12 15 18 21 24 27 30 30