I have the following code:
import java.util.Scanner;
public class Practice {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//System.out.println("Enter quantity:");
//int quantity = input.nextInt();
//System.out.println("You entered: " + quantity);
//System.out.println("Enter price: ");
//double price = input.nextDouble();
//System.out.println("You entered: " + price);
System.out.println("Enter city: ");
String city = input.nextLine();
System.out.println("You entered: " + city);
System.out.println("Enter state code: ");
String state = input.next();
System.out.println("You entered: " + state);
}
}
When I run the program with the middle section commented out like this, it works correctly. But when I uncomment it, it messes up the last block by printing the following lines simultaneously:
Enter city:
You entered:
Enter state code:
Why is this happening, and how can I fix it?