Question
Sort letters in word in ascending order and print missing letters in the wordÂ
Enter the word:
DELHI
Original Word:DELHI
Sorted Word:DEHIL
Missing Letter:FGJK
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class SortAndPrintMissingLetters
{
public static void main()
{
int i,len=0,j=0;
String wd="",newWd="",missingLetters="";
char ch= ' ',ch1=' ',temp=' ';
char characters[];
char startPosition=' ',endPosition=' ';
boolean characterFound=false;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the word:");
wd=sc.next();
len=wd.length();
wd=wd.toUpperCase();
characters=new char[len];
for(i=0;i< len;i++)
{
characters[i]=wd.charAt(i);
}
for(i=0;i< len;i++)
{
for(j=0;j< len;j++)
{
if(characters[i]< characters[j])
{
temp=characters[i];
characters[i]=characters[j];
characters[j]=temp;
}
}
}
for(i=0;i< len;i++)
{
newWd=newWd+characters[i];
}
System.out.println("Original Word:"+wd);
System.out.println("Sorted Word:"+newWd);
startPosition=newWd.charAt(0);
endPosition=newWd.charAt(len-1);
for(ch=startPosition;ch<=endPosition;ch++)
{
characterFound=false;
for(i=0;i< len;i++)
{
ch1=newWd.charAt(i);
if(ch==ch1)
{
characterFound=true;
break;
}
}
if(characterFound==false)
{
missingLetters=missingLetters+ch;
}
}
System.out.println("Missing Letter:"+missingLetters);
}
}
Coding Store
Sale
ISC QUESTION PAPERS WITH SOLUTION(PROGRAMMING ONLY)
Sale