0
Explain output
public class Program { public static void main(String[] args) { int i=1; for(;i<5;i++) {i*=i; System.out.print(i);} } } Output 14 public class Program { public static void main(String[] args) { int i=1; for(;i<5;i++) i*=i; System.out.print(i); } } Output 5
1 Answer
0
Output #1:
1 Ă 1 = 1
Then 1 will be printed and then i is being increased so now its value is 2.
2 Ă 2 = 4
So 4 will be printed near the 1 that we already printed.
Then i is being increased again to 5 and loop runs if i is smaller than 5.
Output #2:
The same as the last output but on this one we don't have curly brackets for the loop so the print is done only once which is when the loop is over with value of 5.