sample
int[] array = new int[5];
//1 as an element in the declared array,10,100,1000,Set 10000
array[0] = 1; //Note that the array starts at 0th.
array[1] = 10;
array[2] = 100;
array[3] = 1000;
array[4] = 10000;
System.out.println(array[0]); //Print the first value in the array
Method using array declaration {}. Outputs the sum of the 1st and 3rd of the array
sample
int[] array = {1,10,100};
System.out.println(array[0]+array[2]);
for(int i=0; i<array.length; i++) {
System.out.println(array[i]);
}//Output all elements of array array in order
for(int i=array.length-1; i>=0; i--) {
System.out.println(array[i]);
}//Output the contents of the array array in order from the end to the beginning(Take out from the reverse)
//Number of arrays in int i when outputting from the end-Set 1 as the initial value
When outputting from the end For example, if the array array has three lengths, array [0], array [1], and array [2] exist. When extracting from the end, if the initial value of int i is the number of arrays, it will be extracted from array [3] and an error will occur. By incrementing -1, the initial values array [2] to [0] are output in descending order with i--.
Recommended Posts