+ 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

7th Jun 2018, 8:43 AM
youk
4 Respostas
+ 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
7th Jun 2018, 8:54 AM
***
+ 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.
7th Jun 2018, 8:50 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
add: if you want to affect the array elements so no[0]++; // now value of array first elements become 16.
7th Jun 2018, 9:27 AM
Nitish kumar jha
Nitish kumar jha - avatar
+ 3
thankx
7th Jun 2018, 9:33 AM
youk