Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] str = scanner.nextLine().split(",");
- for (int i = 0; i < str.length-1; i++) {
- if (str[i].equals(str[i+1])&& i+1!=str.length-1){
- continue;
- } if (!str[i].equals(str[i+1]) && i+1!=str.length-1){
- System.out.print(str[i]+",");
- } else if (!str[i].equals(str[i+1]) && i+1==str.length-1){
- System.out.print(str[i]+","+str[i+1]);
- } else {
- System.out.print(str[i+1]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement