-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweek5_1.java
91 lines (46 loc) · 1.17 KB
/
week5_1.java
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import java.util.Scanner;
public class week5_1 {
static class Phone{
private String name, tel;
Phone(String name, String tel){
this.name = name;
this.tel = tel;
}
}
public static void main(String[] args) {
try {
System.out.print("인원수>>");
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
Phone p[] = new Phone[size];
for(int i =0; i < size; i++) {
System.out.print("이름과 전화번호(이름과 번호는 빈 칸 없이 입력)>>");
String name = sc.next();
String tel = sc.next();
p[i] = new Phone(name, tel);
}
System.out.println("저장되었습니다...");
do {
System.out.print("검색할 이름>>");
String search = sc.next();
if(search.equals("그만")) {
break;
}
else {
for(int i =0; i < size; i++) {
if(search.equals(p[i].name)) {
System.out.println(p[i].name + "의 번호는 " + p[i].tel);
}
else {
System.out.println(p[i].name + "이 없습니다.");
}
}
}
}while(true);
sc.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}