Output? Can u elaborate output of the code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Output? Can u elaborate output of the code

int i; for(i=1;i<5;i++) i*=i; System.out.println(i);

29th Jun 2017, 2:10 PM
Jayram
Jayram - avatar
1 Answer
0
Iteration 1: i=1 Statement 1: i*=i on execution i = i*i which is i= 1*1 which gives you i = 1 i++ check whether i<5 or not? It is then Iteration 2: i=2 Statement 1: i*=i which is i = 2*2 which gives you i=4 check whether i<5 or not? 5<5 which is false loop breaks Now Statement 2: print i which is equal to 5 Output of this code will be 5
30th Jun 2017, 2:55 AM
SHIVANSH NEMA
SHIVANSH NEMA - avatar