This is a java program for school students on arranging a String in ascending order using conditional operator.
import java.io.*;
class String1
{
String str;
char ch[],c1;
int i,j,len;
boolean bool;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
void show() throws Exception
{
System.out.println("\nEnter the string:");
str=br.readLine();
ch=new char[len];
for(i=0;i< len;i++)
ch[i]=str.charAt(i);
System.out.println("Original String:"+str);
for(i=0;i< len-1;i++)
{
for(j=i+1;j< len;j++)
{
bool=(ch[i] >ch[j])?true:false;
if(bool)
{
c1=ch[i];
ch[i]=ch[j];
ch[j]=c1;
}
}
}
str=new String(ch);
System.out.println("String in Ascending order:"+str);
}
public static void main(String args[])throws Exception
{
String1 ob=new String1();
ob.show();
}
}
Related Post: BlueJ Programs on String/Sentence
No comments:
Post a Comment