firstly i created a boolean then set it to true so as to enable the first run... then subsequent runs would be based on the user input.
boolean emptyLine = true;
String name; int quantity; double price;
Scanner scan = new Scanner(System.in);
while(emptyLine != false) //repeatedly request user input if input is not empty
{
//ask the user for the quantity of items being purchased.
System.out.println("Enter name of item: Enter quantity of item purchased: Enter price of item being purchased: ");
input = scan.nextLine(); //should read the line of input
item = //name of item from the line of input.
quantity = scan.nextInt(); //should get the quantity from the line of input
price = scan.nextDouble(); //get the price from the line of input
if(input.length() >= 0)
{
emptyLine = true;
}
else
{
emptyLine = false;
}
}
I am trying to write a code to check if user input is empty or not. such that if user input is empty, the user is requested to enter a valid input or exit.
for example, if the user enters a space, I want my program to accept it, but if the user presses the ENTER button then it should be rejected.