Please correct the error for this code: import java.util.Scanner; // import Scanner class required to accept input from user public class Main // To declare 3 variables for employee ID, Name and Salary { public static void main(String[] args) { int i; int num; Scanner obj = new Scanner(System.in); System.out.print("Enter number of employees: "); // user should enter the number of employees int num = obj.nextInt(); Employee emp[] = new Employee[num]; // create an array of num for (i = 0; i < num; i++) { Employee e = new Employee(ID, Name, Sal); emp[i] = e; System.out.println("Employee details: "); // To store the employees details System.out.print("Enter ID: "); int ID = obj.nextInt(); System.out.print("Enter Name: "); String Name = obj.nextLine(); System.out.print("Enter Salary: "); double Sal = obj.nextDouble(); } System.out.println("Employees details: "); // To display the employees details public void show() { System.out.println("Sl No: " + (i+1) + "ID: " + ID + "Name: " + Name + "Salary: " + Sal); } for (i = 0; i < num; i++) { emp[i].show(); } } }
Please correct the error for this code:
import java.util.Scanner; // import Scanner class required to accept input from user
public class Main // To declare 3 variables for employee ID, Name and Salary
{
public static void main(String[] args)
{
int i;
int num;
Scanner obj = new Scanner(System.in);
System.out.print("Enter number of employees: "); // user should enter the number of employees
int num = obj.nextInt();
Employee emp[] = new Employee[num]; // create an array of num
for (i = 0; i < num; i++)
{
Employee e = new Employee(ID, Name, Sal);
emp[i] = e;
System.out.println("Employee details: "); // To store the employees details
System.out.print("Enter ID: ");
int ID = obj.nextInt();
System.out.print("Enter Name: ");
String Name = obj.nextLine();
System.out.print("Enter Salary: ");
double Sal = obj.nextDouble();
}
System.out.println("Employees details: "); // To display the employees details
public void show()
{
System.out.println("Sl No: " + (i+1) + "ID: " + ID + "Name: " + Name + "Salary: " + Sal);
}
for (i = 0; i < num; i++)
{
emp[i].show();
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images