Advertisement
Aleks_Tor

Remove duplicates [first one]

Jun 13th, 2021
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. public class Main {
  2.  
  3.     public static void main(String[] args) {
  4.         Scanner scanner = new Scanner(System.in);
  5.         String[] str = scanner.nextLine().split(",");
  6.  
  7.         for (int i = 0; i < str.length-1; i++) {
  8.             if (str[i].equals(str[i+1])&& i+1!=str.length-1){
  9.                 continue;
  10.             } if (!str[i].equals(str[i+1]) && i+1!=str.length-1){
  11.                 System.out.print(str[i]+",");
  12.             } else if (!str[i].equals(str[i+1]) && i+1==str.length-1){
  13.                 System.out.print(str[i]+","+str[i+1]);
  14.             } else {
  15.                 System.out.print(str[i+1]);
  16.             }
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement