+ 2

Please answer

Why is the last output of the code 10 Code :- public class Program { public static void main(String[] args) { int i; for(i=0;i<10;i++){ System.out.println(i); } System.out.println(i); } }

30th Mar 2021, 9:23 AM
Parth Shendge
2 ответов
+ 7
Parth Shendge Because you have printed the value of i outside the loop after checking condition 9 < 10 , 9 will be print and i will be increase by 1 so i would be 10
30th Mar 2021, 9:33 AM
A͢J
A͢J - avatar
+ 1
First println method gives you 0 1 2 3 4 5 6 7 8 9 It ends when method checks if 10 is less then 10 which returns false because 10 is not less then 10 its equal. Second print method gives you the 10 9 <- for loop & print method ends here i =10; 10 <- second println method prints i
30th Mar 2021, 3:21 PM
D_Stark
D_Stark - avatar