SHARE
TWEET

Three Groups

elena_veskova Dec 7th, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.Scanner;
  4.  
  5. public class Task {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         Scanner scanner = new Scanner(System.in);
  10.         String[] strArray = scanner.nextLine().split("\\s+");
  11.         int[] arr = new int[strArray.length];
  12.  
  13.         ArrayList<Integer> rem0 = new ArrayList<>();
  14.         ArrayList<Integer> rem1 = new ArrayList<>();
  15.         ArrayList<Integer> rem2 = new ArrayList<>();
  16.  
  17.         for (int i = 0; i < strArray.length; i++) {
  18.             arr[i] = Integer.parseInt(strArray[i]);
  19.             if (arr[i] % 3 == 0) {
  20.                 rem0.add(arr[i]);
  21.             } else if (arr[i] % 3 == 1) {
  22.                 rem1.add(arr[i]);
  23.             } else {
  24.                 rem2.add(arr[i]);
  25.             }
  26.         }
  27.         System.out.println(rem0.toString().replace("[", "").replace("]", "").replace(",", ""));
  28.         System.out.println(rem1.toString().replace("[", "").replace("]", "").replace(",", ""));
  29.         System.out.println(rem2.toString().replace("[", "").replace("]", "").replace(",", ""));
  30.     }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top