Welcome friends to Blogger Codemaster. This is our another post. So in this post, I would like to give you a Java program to remove the repeating letters from a word.
So let's get started with our today's topic - PROGRAM TO REMOVE REPEATING LETTERS.
QUESTION
Write a Java program to accept a word in lowercase and display the new word after removing all the repeated letters.
FULL CODE
import java.util.*;
public class NoRepeat
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.println("Enter a word: ");
String word = in.next();
// Converts the string to Lower Case.
word = word.toLowerCase();
// Variable for string new word.
String w1="";
for(int i=0;i<word.length();i++)
{
// Checks the first Index of the character.
if(word.indexOf(word.charAt(i))==i)
w1=w1+word.charAt(i);
}
// Prints the new word.
System.out.println("The new word after removing all the repeated letters: "+w1);
}
}
VARIABLE DESCRIPTION
Variable | Data Type | Description |
word | String | Word which is taken as input. |
w1 | String | New Word Generated. |
i | int | Loop Variable. |
OUTPUT
Here, we come to the end of our another post. We will discuss various other interesting topics in our upcoming posts.
So uptil then I bid you a goodbye😇.
Please follow our 👉blog and comment💬 below for any queries.