-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayListEx.java
More file actions
31 lines (25 loc) · 841 Bytes
/
Copy pathArrayListEx.java
File metadata and controls
31 lines (25 loc) · 841 Bytes
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
package generics;
import java.util.ArrayList;
import java.util.Scanner;
public class ArrayListEx {
public static void main(String[] args) {
ArrayList<String> a = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
for(int i = 0; i < 4; i++) {
System.out.print("이름을 입력하세요 >> ");
String s = scanner.next();
a.add(s);
}
for(int i = 0; i < a.size(); i++) {
String name = a.get(i);
System.out.print( name + " ");
}
int longestIndex = 0;
for(int i = 0; i < 4; i++) {
if(a.get(longestIndex).length() < a.get(i).length())
longestIndex = i;
}
System.out.println("\n가장 긴 이름은 : " + a.get(longestIndex));
scanner.close();
}
}