public static void main(String[] args) {
int[] numbers = new int[8];
numbers[1] = 3;
numbers[4] = 99;
numbers[6] = 2;
int x = numbers[1];
numbers[x] = 42;
numbers[numbers[6]] = 11;
for(int i=0; i<8; i++) {
System.out.print(numbers[i] + " ");
}
System.out.println(); }
}
//output:
0 3 11 42 99 0 2 0
name.length
for(int i=0; i<numbers.length; i++) {
System.out.print(numbers[i] + " ");
}
//output
0 3 11 42 99 0 2 0
//sometimnes we assign each element a value in loop
for(int i=0; i<8; i++) {
numbers[i] = 2 * i;
System.out.println(numbers[i]);
}
//output.
0
2
4
6
8
10
12
14
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter