write a program in java to accept the names of any 10 cities of India along with their population in two different arrays.Sort the population array in descending order.Print the population array with the corresponding names of the cities
Answers
Answer:
BELOW
Explanation:
Write a java program to accept and store 10 city names in a single dimensional array and enter a new name and ... array and enter a new name and check whether it is there or not by using selection Sort algorithm ... 34.5K people helped ... System.out.println("Enter city name to be checked in the given list");.
HOPE IT HELPED
Answer:
Explanation:
import java.util.*;
public class Prg3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String city[]=new String[10];
double population[]=new double[10];
for(int a=0;a<10;a++){
System.out.println("Enter name of a city : ");
city[a]=sc.next();
System.out.println("Enter population of "+city[a]);
population[a]=sc.nextDouble();
}//Accepted all the info
double temp=0.0D;
String tem="";
for(int i=0;i<9;i++){
for(int j=0;j<(9-i);j++){
if(population[j]>population[j+1]){
temp=population[j];
population[j]=population[j+1];
population[j+1]=temp;
tem=city[j];
city[j]=city[j+1];
city[j+1]=tem;
}
}
}//Sorted in ascending order
//Swapping the elements to get them in descending order
for(int m=0;m<5;m++){
double t=population[m];
String te=city[m];
population[m]=population[10-m-1];
city[m]=city[10-m-1];
population[10-m-1]=t;
city[m]=te;
}
System.out.println("The cities with their population in decreasing order : ");
int pos=1;
for(int ij=0;ij<=10;ij++){
System.out.println(pos+">"+city[ij]+" with its population of "+population[ij]+" people");
pos++;
}
}
}