My issue
i can’t run this code
Learning course: Practice Java
Problem Link: Rearrange Code Practice Problem in Java - CodeChef
i can’t run this code
Learning course: Practice Java
Problem Link: Rearrange Code Practice Problem in Java - CodeChef
@brindha04
this will be the correct rearrangement
int i = 1;
while (i <= 10) {
System.out.print(i);
i = i + 1;
}
Correct arrangement of code
int i = 1;
while (i <= 10) {
System.out.print(i);
i = i + 1;
}
// Here at first we are initializing i as 1. And running a while loop with a condition that i must be less than or equal to 10. In first round the value of i will be 1, then it will be printed, and after printing the value of i will be increased to 2 by i = i + 1 ( as i = 1 + 1). Then in the next round the value of i will be 2, and after checking that 2 is less than 10, it will enter the loop and print the value as 2, and in next step it will again incremented to 3. And this process will continue till i becomes 11, and when i becomes 11, when it will check at while loop, the condition becomes false. And it will jump out of the loop. And our final output will be from 1 to 10.