How To Use Array in Java Programming Language
The Following script is the simplest way to declaring and using Array in Java:
public class UseArray {
public static void main(String[] args) {
// first example
int[] x = {1,2,3,4,5,6,7,8,9,10}
System.out.println("x[0] = "+ x[0]);
//second example
int y[];
y = new int[3];
y[0] = 1;
y[1] = 2;
y[2] = 3;
System.out.println("y[1] = "+ y[1]);
//third example
//looping through array
for(int z : y){
System.out.println("y["+ (z - 1) +"] :"+ z);
}
}
}
output:
or you can see the video tutorial here:
ShadowOfBdg© - All rights reserved.
No comments:
Post a Comment