Create 3 arrays that will hold 5 employee information:
Name
Address
For example: empName[0], empAddress[0], empEmail[0] should belong to the same employee.
We will output the employee's information by using int variable as index.
The user will select what index will be printed on the console so you need to use the java.util.scanner.
import java.util.Scanner;
public class App {
/** Main Method */
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in); // Create a Scanner
String empName[] = new String[5];
String empAddress[] = new String[5];
String empEmail[] = new String[5];
for (int i = 0; i < 5; i++) {
System.out.print("Name: ");
empName[i] = keyBoard.nextLine();
System.out.print("Address: ");
empAddress[i] = keyBoard.nextLine();
System.out.print("Email: ");
empEmail[i] = keyBoard.nextLine();
}
System.out.print("Select what index will be printed [0-4]: ");
int index = keyBoard.nextInt();
System.out.println("Name: " + empName[index]);
System.out.println("Address: " + empAddress[index]);
System.out.println("Email: " + empEmail[index]);
keyBoard.close();
}
}
Comments
Leave a comment