Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner userInput = new Scanner(System.in);
- String[] stringArray = userInput.nextLine().split(",");
- Integer[] integerArray = new Integer[stringArray.length];
- List<Integer> positiveInt = new ArrayList<>();
- List<Integer> equalsNull = new ArrayList<>();
- for (int i = 0; i < integerArray.length; i++) {
- integerArray[i] = Integer.parseInt(stringArray[i]);
- }
- for(Integer i: integerArray) {
- if(i > 0) {
- positiveInt.add(i);
- } else if(i == 0) {
- equalsNull.add(i);
- }
- }
- List<Integer> finalList = new ArrayList<>(positiveInt);
- finalList.addAll(equalsNull);
- System.out.println(finalList.toString().replaceAll("(^\\[|\\]$)", "").replaceAll("\\s", ""));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment