Computer Science, asked by Imnotthatsmart, 3 months ago

Java Array Program:
Read name of the cities and temperature and display the name of hottest city.

Answers

Answered by BrainlyProgrammer
7

Answer:

//Program to print the name of hottest city

import java.util.*;

class abc{

public static void main(String ar []){

Scanner sc=new Scanner (System.in);

System.out.println("Enter no. of cities");

int n=sc.nextInt();

int temp[]=new int[n];

String cities[]=new String[n];

for(int I=0;I<n;I++){

temp[I]=sc.nextInt();

cities[I]=sc.nextLine();

}

for(int i=0;i<n-1;i++){

for(int j=0;j<n-i-1;j++){

if(temp[j]<temp[j+1]){

int t=temp[j];

temp[j]=temp[j+1];

temp[j+1]=t;

String ab=cities[j];

cities[j]=cities[j+1];

cities[j+1]=ab;

}

}

}

System.out.println("Highest temperature:- "+temp[0]+" in "+cities[0]);

}

}

Hint:-

  • Arrange the temperature array in descending order
  • At the same time arrange cities array
  • Finally, display the first element
Similar questions