I'm having problem with outputting two separate questions. The code is:
System.out.println("Please enter full name: ");
String name = keyboard.nextLine();
while (name.length() >= 21)
{
System.out.println("Name is invalid, please re enter:");
name = keyboard.nextLine();
}
System.out.println("Please enter reference number: ");
String reference = keyboard.nextLine();
while (reference.length() > 6) {
System.out.println("Refrence incorrect, please re enter");
reference = keyboard.nextLine();
}
while (!reference.matches("(?i)[A-Z]{2}[0-9]{3}[A-Z]")) {
System.out.println("Reference is incorrect, please re-enter:");
reference = keyboard.nextLine();
however what is being output resembles:
Please enter full name:
Please enter reference number:
with no room for me to input the name or reference. Even when i do, it asks for the reference again. Can anybody spot any problems in my code? (I'm a beginner if you couldn't tell my the un elegant coding haha)
the code that came before this is:
Scanner keyboard = new Scanner(System.in);
System.out.println("Please select from the following options:");
System.out.println("1. Enter new Policy");
System.out.println("2. Display summary of policies");
System.out.println("3. Display summary of policies for selected month");
System.out.println("4. Find and display Policy");
System.out.println("0. Exit");
int option = keyboard.nextInt();
if (option == 1) {
System.out.println("Please enter full name: ");
...