Computer Science, asked by anusuhamaji, 5 months ago

Write a Java program to input temperature of 10 cities in an array of integers and 10 city names in an array of strings.sort the temperature array using bubble sort technique along with the corresponding city names and print the sorted temperature array along with corresponding cities.​

Answers

Answered by weotikabali
1

Answer:

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]);

}

}

}

Similar questions