forked from Nnamdikeshi/Java2545examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInputArrayList.java
More file actions
39 lines (25 loc) · 901 Bytes
/
Copy pathUserInputArrayList.java
File metadata and controls
39 lines (25 loc) · 901 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
32
33
34
35
36
37
38
39
package week4_data_structures;
import java.util.ArrayList;
import java.util.Scanner;
/**
* Ask user for data, store in ArrayList<String></String>
*/
public class UserInputArrayList {
static Scanner stringScanner = new Scanner(System.in);
public static void main(String[] args) {
ArrayList<String> userData = new ArrayList<String>();
while (true) {
System.out.println("Please type in data, or press Enter to quit");
String data = stringScanner.nextLine();
if (data.length() == 0) { // If the user just presses Enter, the length of text is 0.
break;
}
userData.add(data);
}
System.out.println("Thank you, here is all of the data you entered:");
for (String input : userData) {
System.out.println(input);
}
stringScanner.close();
}
}