SHARE
TWEET

Strange Order

a guest Jan 21st, 2019 160 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.*;
  2. import java.util.Arrays;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.  
  9.         Scanner sc = new Scanner(System.in);
  10.         String[] listStr = sc.nextLine().split(",");
  11.         int length = listStr.length;
  12.         int[] array = new int[length];
  13.  
  14.         for (int i = 0; i < length; i++) {
  15.             array[i] = Integer.parseInt(listStr[i]);
  16.         }
  17.         StringBuilder avg=new StringBuilder();
  18.         StringBuilder below=new StringBuilder();
  19.         StringBuilder above=new StringBuilder();
  20.  
  21.  
  22.         for (int i = 0; i < length; i++) {
  23.  
  24.             if (array[i] < 0) {
  25.                 below = below.append(array[i]);
  26.                 below=below.append(",");
  27.  
  28.             }
  29.             if (array[i] > 0) {
  30.                 above = above.append(array[i]);
  31.                 above=above.append(",");
  32.             }
  33.             if (array[i] == 0) {
  34.                 avg = avg.append(array[i]);
  35.                 avg=avg.append(",");
  36.             }
  37.  
  38.         }
  39.         System.out.print(below);
  40.         System.out.print(avg);
  41.         System.out.println(above.substring(0, above.length()-1));
  42.  
  43.     }
  44. }
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