Write a program to assign name of two cities and display them in different lines.
Answers
class SortCity
{
public static void main(String arg[])
{
String name[]=new String[10];
int l=arg.length;
String temp;
for(int i=0;i<l;i++)
{
name[i]=arg[i];
}
for(int j=0;j<l;j++)
{
for(int k=j+1;k<l;k++)
{
if((name[j].compareTo(name[k]))<0)
{
temp=name[j];
name[j]=name[k];
name[k]=temp;
}
}
}
System.out.println("Sorted City Are-");
for(int i=0;i<l;i++)
{
System.out.println(name[i]);
}
}
}
/*OUTPUT
D:\javapro>javac SortCity.java
D:\javapro>java SortCity pune nagar solapur thane satara baramati
Sorted City Are-
thane
solapur
satara
pune
nagar
baramati
*/