+ 1
what does new int[5] mean?
int[]arr=new int[5] what does it mean? can someone please explain it to me? it would be better if you explain with an example ☺
4 odpowiedzi
+ 3
class Main {
public static void main(String[] args) {
//This is how to declare an array in java,this array is of
//type integer and has 3 elements
int[] arr = new int[3];
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
System.out.println(arr[0]);//0
System.out.println(arr[1]);//1
System.out.println(arr[2]);//2
System.out.println(arr[3]);//outputs an error
}
}
+ 2
so new int[] mean I can add only 3 arr?
+ 2
new int[] means initialize an array object named arr and has a given number of elements,you can choose any number you want,but it will be of the type declared yet.
0
It basically mean " create an array of integer(number) of 5 items
Eg,[5,8,12,6,8]