In this program we can know how to store the names of employees in a arraylist.
package collections;
import java.util.ArrayList;
import java.util.Scanner;
public class EmployeeManagement {
public static void main(String[] args) {
ArrayList<String> empList=new ArrayList<String>();
Scanner sc=new Scanner(System.in);
System.out.println("How many Employee names do you want to enter in the system:");
int num=sc.nextInt();
EmployeeManagement eman=new EmployeeManagement();
eman.addEmpName(num,empList);
System.out.println("The Employees in the System are: ");
for (int i=0;i<num;i++)
{
String name=empList.get(i);
System.out.println(name);
}
}
public void addEmpName(int no,ArrayList<String> empNameList)
{
Scanner sc=new Scanner(System.in);
for(int i=0;i<no;i++)
{
System.out.println("Enter the name of Employee: ");
String name=sc.nextLine();
empNameList.add(name);
}
}
}
package collections;
import java.util.ArrayList;
import java.util.Scanner;
public class EmployeeManagement {
public static void main(String[] args) {
ArrayList<String> empList=new ArrayList<String>();
Scanner sc=new Scanner(System.in);
System.out.println("How many Employee names do you want to enter in the system:");
int num=sc.nextInt();
EmployeeManagement eman=new EmployeeManagement();
eman.addEmpName(num,empList);
System.out.println("The Employees in the System are: ");
for (int i=0;i<num;i++)
{
String name=empList.get(i);
System.out.println(name);
}
}
public void addEmpName(int no,ArrayList<String> empNameList)
{
Scanner sc=new Scanner(System.in);
for(int i=0;i<no;i++)
{
System.out.println("Enter the name of Employee: ");
String name=sc.nextLine();
empNameList.add(name);
}
}
}
0 comments:
Post a Comment