-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreeGroups.java
More file actions
35 lines (30 loc) · 913 Bytes
/
ThreeGroups.java
File metadata and controls
35 lines (30 loc) · 913 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
import java.util.Scanner;
public class ThreeGroups {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String input=sc.nextLine();
String[]arr=input.split(" ");
int[]arr2=new int[arr.length];
StringBuilder remainder0=new StringBuilder();
StringBuilder remainder1=new StringBuilder();
StringBuilder remainder2=new StringBuilder();
for (int i = 0; i < arr.length; i++) {
arr2[i]=Integer.parseInt(arr[i]);
if (arr2[i]%3==0) {
remainder0.append(arr2[i]);
remainder0.append(' ');
}
else if (arr2[i]%3==1) {
remainder1.append(arr2[i]);
remainder1.append(' ');
}
else if (arr2[i]%3==2) {
remainder2.append(arr2[i]);
remainder2.append(' ');
}
}
System.out.println(remainder0.toString());
System.out.println(remainder1.toString());
System.out.println(remainder2.toString());
}
}