Ques:-Accept a word arrange all the character in alphabetical order of a word and
display only those alphabets which are not present in word.
/*Accept a word arrange all the character in alphabetical order of a word and
* display only those alphabets which are not present in word*/
import java.io.*;
class sot_word
{
public static void main(String args[])throws IOException//Main function
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String st;
int len,i,x,j;
char ch,temp;
System.out.println("Enter a word");
st=br.readLine();
len=st.length();
st=st.toUpperCase();
char a[]=new char[len];//Array to store the each alphabet of word
for(i=0;i<len;i++)//Storing character in array
{
ch=st.charAt(i);
a[i]=ch;
}
for(i=0;i<len;i++)//Sorting alphabet using bubble sort technique
{
for(j=0;j<len-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
System.out.println("Sorted Word");//Printing sorted word
for(i=0;i<len;i++)
{
System.out.print(a[i]);
}
System.out.println();
for(ch=a[0],x=0;ch<=a[len-1];ch++)//Converting word into give format
{
if(ch==a[x])
{
x++;
}
else
{
System.out.print(ch);//Printing the result
}
}
}
}
display only those alphabets which are not present in word.
/*Accept a word arrange all the character in alphabetical order of a word and
* display only those alphabets which are not present in word*/
import java.io.*;
class sot_word
{
public static void main(String args[])throws IOException//Main function
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String st;
int len,i,x,j;
char ch,temp;
System.out.println("Enter a word");
st=br.readLine();
len=st.length();
st=st.toUpperCase();
char a[]=new char[len];//Array to store the each alphabet of word
for(i=0;i<len;i++)//Storing character in array
{
ch=st.charAt(i);
a[i]=ch;
}
for(i=0;i<len;i++)//Sorting alphabet using bubble sort technique
{
for(j=0;j<len-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
System.out.println("Sorted Word");//Printing sorted word
for(i=0;i<len;i++)
{
System.out.print(a[i]);
}
System.out.println();
for(ch=a[0],x=0;ch<=a[len-1];ch++)//Converting word into give format
{
if(ch==a[x])
{
x++;
}
else
{
System.out.print(ch);//Printing the result
}
}
}
}
No comments:
Post a Comment