-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavapedia.java
More file actions
43 lines (42 loc) · 1.69 KB
/
Javapedia.java
File metadata and controls
43 lines (42 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.Scanner;
public class Javapedia {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("\n**********Javapedia**********");
System.out.println("How many historical figures will you register?");
int people = scan.nextInt();
String[][] database = new String[people][3];
scan.nextLine();
for (int i = 0; i < database.length; i++) {
System.out.println("\n\tFigure " + (i+1));
System.out.print("\t - Name: ");
database[i][0] = scan.nextLine();
System.out.print("\t - Date of birth: ");
database[i][1] = scan.nextLine();
System.out.print("\t - Occupation: ");
database[i][2] = scan.nextLine();
System.out.print("\n");
}
System.out.println("These are the values you stored:");
print2DArray(database);
System.out.print("\nWho do you want information on? ");
String name = scan.nextLine();
for (int i = 0; i < database.length; i++) {
if (database[i][0].equals(name)) {
System.out.println("\tName: " + database[i][0]);
System.out.println("\tDate of birth: " + database[i][1]);
System.out.println("\tOccupation: " + database[i][2]);
}
}
scan.close();
}
public static void print2DArray(String[][] array) {
for (int i = 0; i < array.length; i++) {
System.out.print("\t");
for (int j = 0; j < array[i].length; j++) {
System.out.print(array[i][j] + " ");
}
System.out.print("\n");
}
}
}