I keep having InputMismatchException error every time I type the name of the person in the Scanner?

35 Views Asked by At

what is the problem with my code and why do I have the InputMismatchException error every time I type the name in the console ?

Scanner sc = new Scanner(System.in);
        System.out.println("How many People are there ? (employee and students included)");

        int  numPeople = sc.nextInt();
        Person[] personArray = new Person[numPeople];
        Student[] studentsArray = new Student[numPeople];
        Employee[] employeesArray = new Employee[numPeople];

        int i=0;

        while(i < numPeople) {
            System.out.println("Please enter the name and age of the person");
            String name = sc.nextLine();
            int age = sc.nextInt();sc.nextLine();
            Person person = new Person(name, age);
            personArray[i] = person;
            i++;
0

There are 0 best solutions below