Categories
Class 10 Class 11 Class 12

Removing Repeated Letters From A String

Write a program to input a string from the user in lowercase form.

Then remove all the repeated letters from the string and keep only single occurrences of the characters present in the string.

Display the final string formed after the removal of the extra repeated characters.

Example:
INPUT: applications
OUTPUT: aplictons

import java.io.*;
class Repeated{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("String: ");
        String s = br.readLine().toLowerCase();
        String t = "";
        while(s.length() > 0){
            t += s.charAt(0);
            s = s.replace(Character.toString(s.charAt(0)), "");
        }
        System.out.println(t);
    }
}