Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ThreeGroups {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split(" ");
- int[] numbers = new int[input.length];
- StringBuilder sbZero = new StringBuilder();
- StringBuilder sbOne = new StringBuilder();
- StringBuilder sbTwo = new StringBuilder();
- for (int i = 0; i < input.length; i++) {
- numbers[i] = Integer.parseInt(input[i]);
- if (numbers[i] % 3 == 0) {
- sbZero.append(numbers[i]).append(" ");
- }
- if (numbers[i] % 3 == 1) {
- sbOne.append(numbers[i]).append(" ");
- }
- if (numbers[i] % 3 == 2) {
- sbTwo.append(numbers[i]).append(" ");
- }
- }
- System.out.println(sbZero);
- System.out.println(sbOne);
- System.out.println(sbTwo);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment