write a program to accept and store 5 city names along with pin code . display the original array . rearrange the city names based on alphabetical order and display the sorted names
Answers
Answered by
2
import java.io.*;
class CitySort
{
public static void main (String args[]) throws IOException
{
int n,len,len1,c,i,j,k=0,m=0;
String str[]=new String[5] ;
String s1;
String s2,temp;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for (i=0;i<5;i++)
{
System.out.println(“Enter the string “+i+” of the Array :=> “);
str[i]= br.readLine();
}
System.out.println(“\nSorted Strings are :-”);
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(str[j].compareTo(str[i])<0)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
}
}
System.out.println(str[i]);
}
}
}
Hope it helps you uhh❤️⚡☺️
Similar questions