0

I'm trying to read some inputs from the user(Keyboard) - an int, 3 strings and a boolean. I've mannaged to secssesfully read the int, boolean and 2 strings but the 3rd string doing problems and I didnt find any solution online(anything I saw didnt work). This 3rd string is a string "long" string - more then one word, and thats what causing the problem.

My code

System.out.println("Enter Sportsman's ID, First Name, Family Name, Club Name And Gender(true=male)");
                int id = scanner.nextInt();
                String firstName = scanner.next();
                String lastName = scanner.next();
                String club = scanner.nextLine();
                boolean gender = scanner.nextBoolean();
                
                if(addSportsman(id, firstName, lastName, club, gender) == true) {
                    System.out.println("Added Sucsessfully");
                }
                else System.out.println("This Sportsman Already Exists");

As I said, the problem is with the 3rd String aka club.

The command scanner.nextLine() is what causing the problem - it skips that line and then the code gets stuck

Sample for club input: "Inter Milano"

0 Answers0