I'm a newbie in java from c# background. In c# when i want to make sure the user cannot does null data in the Console Application i make a loop like
static void Main(string[] args)
{
Console.WriteLine("Enter your name : ");
string name = Console.ReadLine();
while (name == "")
{
Console.WriteLine("Enter your name : ");
name = Console.ReadLine();
}
}
Now I want to implement the same in java. I am using
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Enter your name : ");
String pname;
Scanner scan=new Scanner(System.in);
pname=scan.next();
while ("".equals(pname))
{
System.out.println("Enter your name : ");
pname=scan.next();
}
}
But when a null value is entered, the output doesn't show the Enter your name again it only moves one line waiting for a value to be entered.
What am i doing wrong?
nullvalue?