public class StringSorting {
public static void main(String[] args) {
String[] str={"Zero","Hello","Hi","My","egg"};
for(int i=0;i<str.length;i++)
{
for(int j=0;j<i;j++)
{
if(str[j].compareToIgnoreCase(str[j+1])<0)
{
String temp=str[j];
str[j]=str[j+1];
str[j+1]=temp;
}
}
}
System.out.println("The string after sorting is: ");
for(int i=str.length-1;i>=0;i--)
System.out.println(str[i]);
}
}
0 comments:
Post a Comment