When doing homework,I found an error when I'm using do while loop and while loop. It successfully run the variable initialization in do while loop.But not in the while loop.Why is that?What is the reason?
class Example{
public static void main(String args[]){
int x=100;
int a,b;
do{
a=10;
}while(x>0);
while(x>0){
b=10;
}
System.out.println(a);
System.out.println(b);
}
}
Error:
variable b might not have been initialized
System.out.println(b);
^1 error