write a java program to accept and store 10 city names in a single dimensional array and enter a new name and check whether it is there or not by using selection Sort algorithm
Answers
Program
import java.io.*;
import java.util.*;
public class Main{
public static void main(String args[]){
int[] arr = new int[10];
Scanner sc = new Scanner(System.in);
System.out.println("Enter 10 city name:")
for (int i = 0 ; i < 10 ; i++ ){
arr[i] = sc.nextLine();
}
System.out.println("Enter city name to be checked in the given list");
String st = sc.nextLine();
int i = 0;
while ( i < 10 ){
if ( arr[i].equals(st) ){
System.out.println("city name found at "+(i+1)+" position");
break;
}
i++;
}
}
}
Output
Enter city name to be checked in the given list:
vijayawada
hyderabad
kolkatha
pune
chennai
jaipur
ahmedabad
surat
bangalore
mumbai
Enter city name to be checked in the given list:
pune
city name found at 4 position
-----hope this helps :)