+ 3
Array
int a,b,c,d,e; a = 15; b = 20; c = 25; d = 30; e = 35; int[] no = {a,b,c,d,e}; System.out.println(no[0]); //15 a++; //increment 1 System.out.println(no[0]); // why 15
4 Answers
+ 19
the incremented value of a is after assigning the value of the array - no.
Bisht Boy I'm changing ur code slightly that u can understand better.
int a,b,c,d,e;
a = 15;
b = 20;
c = 25;
d = 30;
e = 35;
a++;
int[] no = {a,b,c,d,e};
System.out.println(no[0]); //16
or ---------------------- or
int a,b,c,d,e;
a = 15;
b = 20;
c = 25;
d = 30;
e = 35;
int[] no = {a,b,c,d,e};
System.out.println(no[0]); //15
a++; //increment 1
int [] no_2 ={a,b,c,d,e}
System.out.println(no_2[0]); // 16
+ 7
You assigned the values of variables a, b, c, d, and e to array no. Incrementing the variables after the values are already assigned to the array does not affect the content of the array.
+ 3
add:
if you want to affect the array elements so
no[0]++; // now value of array first elements become 16.
+ 3
thankx