forked from google/codeu_coding_assessment_2017
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClump.java
More file actions
30 lines (30 loc) · 952 Bytes
/
Clump.java
File metadata and controls
30 lines (30 loc) · 952 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
import java.util.*;
public class Clump {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
ArrayList<String> list = new ArrayList<String>();
ArrayList<String> list2 = new ArrayList<String>();
while (!input.hasNext("stop")){
String s = input.next();
list.add(s);
}
int size = list.size();
for (int i=0; i< size; i++){
if (i%2 ==0 && i!=(size-1)){
String combine = "(" + list.get(i) + " " + list.get(i+1) + ")";
list2.add(combine);
}
}
if (size%2 !=0){
list2.add(list.get(size-1));
}
System.out.println("");
System.out.println("Please enter a sequence of strings separated");
System.out.println("by spaces. End the sequence with the sentinel");
System.out.println("value \"stop\", followed by a return.");
System.out.println("");
System.out.println("Your original list: " + list);
System.out.println("");
System.out.println("Your clumped list: " + list2);
}
}