+ 14
I NEED explaination
int n=2; int m=4; for (int i=2;i<m;i++){ n=n*n; } System.out.println(n); Output is 16. Please explain it.
12 Answers
+ 10
i=2: n=2*2=4
i=3: n=4*4=16
loop terminates.
prints n
+ 26
nothing else to write 👍😉
+ 7
As value of i goes from i=2 to i=3, the for loop will run twice
Firstly,
n = 2*2 = 4
Secondly,
n = 4*4 = 16
And then it prints the value of n -> 16
+ 6
Thanks you all😉😉
+ 5
Here, n=2 and m=4;
The loop starts from 2 and continues until i<4;
so, when i=2....n=n*n=n=2*2=4;
again, when i=3....n=n*n=4*4=16
so output is 16
+ 5
Here I value should be 2 so 2 times only execute for loop so u get the n value is 16..
+ 4
1)n = 2 × 2, i = 2
2)n =4 × 4, i = 3
n = 16
+ 4
for(I=0;I<m;I++)
u get the output is 65536
I=0
n=2
n=n*n
n=2*2=4
next I should be increment by 1
now n=4
4*4=16
next I value is 2
now n=16
16*16=256
now I value is 3
now n=256
256*256=65536
next I value is 4
it should not be less than m value it is equal, so came outside for loop and print n value.
0
+6
0
+5
0
@pegasus made damn good response :)