Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Main
- {
- static String removeDuplicateElements(char str[], int n)
- {
- // Used as index in the modified string
- int index = 0;
- // Traverse through all characters
- for (int i = 0; i < n; i++)
- {
- // Check if str[i] is present before it
- int j;
- for (j = 0; j < i; j++)
- {
- if (str[i] == str[j])
- {
- break;
- }
- }
- // If not present, then add it to
- // result.
- if (j == i)
- {
- str[index++] = str[i];
- }
- }
- return String.valueOf(Arrays.copyOf(str, index));
- }
- // Driver code
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- char str[] = input.toCharArray();
- int n = str.length;
- System.out.println(removeDuplicateElements(str, n));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment