Guest User

Untitled

a guest
Oct 2nd, 2021
45
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. public class RemoveDuplicates2 {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String[] line = scanner.nextLine().split(",");
  10. List<Integer> numbers = new ArrayList<>();
  11.  
  12. for(int i = 0; i < line.length; i ++){
  13. numbers.add(Integer.parseInt(line[i]));
  14. }
  15. List<Integer> newList = new ArrayList<>();
  16. for(int i = 0; i < numbers.size();i++){
  17. if(!newList.contains(numbers.get(i))){
  18. newList.add(numbers.get(i));
  19. }
  20. }
  21. for(int i = 0; i < newList.size() - 1;i++){
  22. System.out.print(newList.get(i) + ",");
  23. }
  24. System.out.print(newList.get(newList.size() - 1));
  25. }
  26. }
  27.  
RAW Paste Data