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);
    }
}

4 replies on “Removing Repeated Letters From A String”

Sir,a program is given which states that:
WAP in Java to accept a binary number and convert it to its decimal equivalent using recursive function. Display a suitable message if the binary number is negative and if it does not contain 1 and 0.
Sample Input:
Enter a binary number:110011
Sample Output:
The Decimal Equivalent:51

We first take one character from the string, place it to the new string, and then replace that character with an empty string.
This is repeated as long as the original string has characters left in it.

Leave a Reply