I'm trying 2 create a project in java, but this is the epitome of my problem. I m initialising a variable inside a while loop , now as soon as the while loop ends the variable is unset or simply a=7 doesn't get printed. I have no other choice other than using while loop. i have 2 get the value of a that has been initialized.
package Hotel_room_reservation_system;
import java.awt.*;
import java.lang.*;
import java.io.*;
public class NewClass {
public NewClass()
{
int a;
int z=0;
while(z<10)
{
a=7;
z++;
}
System.out.println(a);
}
}
Then i create a new object of this class.
Current Output
variable a might not have been initialized
REQUIRED OUTPUT
7
HELP.