0

In the code below I want the program to ask the user to enter the details and show it on the screen, but it's working only till loop 1 and from loop 2 it is showing the error shown in the image.

This code asks the user to enter the details of the employee and after that is supposed to show the output on the sceen for some set of people. But after running the program it's working only for loop 1 in loop 2 it's working only when the age* is entered. If I enter the name* also along with the age in loop2* it's showing the error.

     import java.util.scanner;
    //This programme is to store the information of the employes came for the interview
    class details{
        String name;
        int age;
        String designation;
        int DOB;
        int expected_salary;
        public void empdetails(String empname,int emp_age,String design,int dob,int sal)
        { name=empname;
          age=emp_age;

        }
        Scanner input=new Scanner(System.in);
        public void getdetails(){
            System.out.println("Enter the name :");
            String nameI=input.nextLine();
            name=nameI;
            System.out.println("Enter the age:");
            int ageI=input.nextInt();
            age=ageI;       
        }

        public void showdetails(){
            System.out.println("DETAILS :--------");
            System.out.println();
            System.out.println("NAME OF THE EMPLOYEE : "+ name);
            System.out.println("AGE OF THE EMPLOYEE : "+ age);
        }


    }

    public class emp {

        public static void main(String[] args) {
            details input=  new details();  //Creating object as -"input"

           for(int i=0;i<3;i++){
               input.getdetails();

               System.out.println("OUTPUT SCREEN :------");

               input.showdetails();
               System.out.println();
           }
        }

enter image description here

Modus Tollens
  • 4,738
  • 3
  • 34
  • 41
Ayush
  • 31
  • 10

0 Answers0