I'm supposed to create a program that Asks for 3 names, as well as their age. It should ask one name, then their age, then the next and so on. When I compile this program, here is what happens.
Enter name shows up, I enter the name, enter age shows up, I enter the age, then the next set comes up together (Enter name, Enter age, without giving me a chance to enter a name before enter age pops up). The rest is the error messageEnter the persons name:
Tom
Enter the persons age
20
Enter the persons name:
Enter the persons age
Tom
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at Oldest.main(Oldest.java:17)
import java.util.*; public class Oldest { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); String per1name, per2name, per3name; int per1age, per2age, per3age; System.out.println("Enter the persons name: "); per1name = stdin.nextLine(); System.out.println("Enter the persons age"); per1age = stdin.nextInt(); System.out.println("Enter the persons name: "); per2name = stdin.nextLine(); System.out.println("Enter the persons age"); per2age = stdin.nextInt(); System.out.println("Enter the persons name: "); per3name = stdin.nextLine(); System.out.println("Enter the persons age"); per3age = stdin.nextInt(); if((per1age > per2age) && (per1age > per3age)){ System.out.println(per1name + " is the oldest person with the age " + per1age); }else if((per2age > per1age) && (per2age > per3age)){ System.out.println(per2name + " is the oldest person with the age " + per2age); }else System.out.println(per3name + " is the oldest person with the age " + per3age); } }