package Binarysearchprg;
public class Bubblesortstring {
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] str={"saritha","sarayu","benny","hari"};
for (int i = str.length-1; i >=0; i--) {
for (int j = 0; j < i; j++) {
if(str[j].compareTo(str[j + 1]) > -1) {
String temp;
temp=str[j];
str[j]=str[j+1];
str[j+1]=temp;
}
}}
for(int i=0;i<str.length;i++)
{
System.out.println(str[i]+" ");
}
}
}
public class Bubblesortstring {
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] str={"saritha","sarayu","benny","hari"};
for (int i = str.length-1; i >=0; i--) {
for (int j = 0; j < i; j++) {
if(str[j].compareTo(str[j + 1]) > -1) {
String temp;
temp=str[j];
str[j]=str[j+1];
str[j+1]=temp;
}
}}
for(int i=0;i<str.length;i++)
{
System.out.println(str[i]+" ");
}
}
}
No comments:
Post a Comment