Define a class and store the given city names in a single dimensional array. Sort these names in alphabetical order
* using the Bubble Sort technique only.
* INPUT: Delhi, Bangalore, Agra, Mumbai, Calcutta
* OUTPUT: Agra, Bangalore, Calcutta, Delhi, Mumbai
*/
[please please please don't answer if you don't know the answer........ Don't waste your time as well as mine ]
Answers
Answer:
import java. io. *;
public class cities
{
public static void main()
{
String city[] ={"Delhi", "Bangalore", "Agra", "Mumbai", "Calcutta"} ;
String temp
for(int i=0;i<=5-1;i++)
{
for(int j =0;j<=5-1-i;j++)
{
if(city[].compare to(city[j+1)>0)
{
temp=city[j];
city[j] =city[j+1];
city[j+1]=temp;
}
}
}
System.out.println("sorted city names") ;
for(int i=0;i<5;i++)
{
System. out. println(city[i] +"j") ;
}
}
}
Answer:
import java. io. *;
public class cities
{
public static void main()
{
String city[] ={"Delhi", "Bangalore", "Agra", "Mumbai", "Calcutta"} ;
String temp
for(int i=0;i<=5-1;i++)
{
for(int j =0;j<=5-1-i;j++)
{
if(city[].compare to(city[j+1)>0)
{
temp=city[j];
city[j] =city[j+1];
city[j+1]=temp;
}
}
}
System.out.println("sorted city names") ;
for(int i=0;i<5;i++)
{
System. out. println(city[i] +"j") ;
}
}
}