Guest User

Untitled

a guest
May 2nd, 2020
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.List;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.  
  8. public static void main(String[] args) {
  9. Scanner userInput = new Scanner(System.in);
  10. String[] stringArray = userInput.nextLine().split(",");
  11. Integer[] integerArray = new Integer[stringArray.length];
  12. List<Integer> positiveInt = new ArrayList<>();
  13. List<Integer> equalsNull = new ArrayList<>();
  14.  
  15. for (int i = 0; i < integerArray.length; i++) {
  16. integerArray[i] = Integer.parseInt(stringArray[i]);
  17. }
  18. for(Integer i: integerArray) {
  19. if(i > 0) {
  20. positiveInt.add(i);
  21. } else if(i == 0) {
  22. equalsNull.add(i);
  23. }
  24. }
  25. List<Integer> finalList = new ArrayList<>(positiveInt);
  26. finalList.addAll(equalsNull);
  27. System.out.println(finalList.toString().replaceAll("(^\\[|\\]$)", "").replaceAll("\\s", ""));
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment