I've been storming ahead with my Java work at University (I've never done Java prior to this) but I'm stuck with inputs a little bit. The task is to write a basic program that allows the user to input their name, house number, road name and town but when it gets to inputting the road name, it seems to skip and doesn't allow you to enter anything for town.
Now, I've tried a flush buffer but that didn't work since it just overwrites what was input. For example, I put the flush buffer after the road name input and that input would then be ignored.
The problem could also be that white space is breaking things despite me using nextLine and not next.
Here's my code;
import java.util.*;
public class AddressProj {
public static void main(String[] args)
{
Scanner myKeyboard = new Scanner(System.in);
System.out.printf("Please input your surname: ");
String name = myKeyboard.nextLine();
System.out.printf("Please input your house number: ");
int houseNumber = myKeyboard.nextInt();
System.out.printf("Please input your road name: ");
String roadName = myKeyboard.nextLine();
myKeyboard.nextLine(); //Flush buffer
System.out.printf("Please input your town: ");
String town = myKeyboard.nextLine();
System.out.printf("Surname: " + name + "\nHouse Number: " + houseNumber + "\nRoad Name: " + roadName + "\nTown: " + town + "\n");
}
}