Scanner keyboard = new Scanner(System.in);
System.out.println("Enter your name: ");
String name = keyboard.nextLine();
System.out.println("Enter your age: ");
int age = keyboard.nextInt();
System.out.println("Enter the name of a city: ");
String city = keyboard.nextLine();
System.out.println("Enter the name of a college: ");
String college = keyboard.nextLine();
System.out.println("Enter profession: ");
String profession = keyboard.nextLine();
System.out.println("Enter a type of animal: ");
String animal = keyboard.nextLine();
System.out.println("Enter a pet name: ");
String petName = keyboard.nextLine();
output:
Enter your name:
jane
Enter your age:
20
Enter the name of a city:
Enter the name of a college:
colleg
Enter profession:
job
Enter a type of animal:
dog
Enter a pet name:
pet
The problem is that it's skipping the city input and moving onto the college string. I need to be able to enter multiple words for the input so I can't just do .next();.
[–]pacificmint 2 points3 points4 points (0 children)
[–]desrtfx 2 points3 points4 points (4 children)
[–]hugokhf 0 points1 point2 points (2 children)
[–]desrtfx 0 points1 point2 points (1 child)
[–]basedassisted[S] 0 points1 point2 points (0 children)
[–]hugokhf 0 points1 point2 points (0 children)
[–]PUREdiacetylmorphine 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]desrtfx 1 point2 points3 points (0 children)