Problem Link: CodeChef: Practical coding for everyone
Learning course: Learn Java
My issue
i didnt undestand
Problem Link: CodeChef: Practical coding for everyone
Learning course: Learn Java
i didnt undestand
This is the code
class Codechef {
public static void main(String[] args) {
int a = 4;
int b = 1;
while (a != b) {
System.out.print(b + " ");
b = b + 1;
}
}
}
The loop starts with a = 4 and b = 1.
Initially a is not equal to b because 4 != 1. So the code inside loop will execute and b (which is 1) will be printed. Inside the loop b also gets updated to b+1 that is 2.
Now the loop will continue and b
will keep printing until a
becomes equal to b
. That will happen when b
become 4 and the loop will stop. Thus when b
becomes 4, nothing will be printed.