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​

Computer Science Secondary School in Computer Science 8 months ago

  541   0   0   0   0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

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    :)

Posted on 06 Dec 2024, this text provides information on Computer Science related to Secondary School in Computer Science. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Tuteehub forum answer Answers

Post Answer

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.