Find Capital using Switch-Case statement


 

Find Capital using Switch-Case statement

In this section, we are going to find the capital of our states using Switch-Case statement.

In this section, we are going to find the capital of our states using Switch-Case statement.

Find Capital using Switch-Case statement

In this Java Tutorial section, we are going to find the capital of our states using Switch-Case statement. For this, we have created two arrays i.e. array of states and array of capitals. Then we have allowed the user to choose the state and enter the corresponding number. After that, when the user press the enter key, the capital city of that particular state will get displayed on the console.

Here is the code:

 import java.util.*; 
 public class FindCapital {      
      public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      String[] states = {"Andhra Pradesh", "Arunachal Pradesh", "Assam",
     "Bihar", "Chhattisgarh", "Goa", "Gujarat", "Haryana", "Himachal Pradesh",
     "Jammu and Kashmir", "Jharkhand", "Karnataka", "Kerala", "Madhya Pradesh", 
     "Maharashtra","Manipur", "Meghalaya", "Mizoram", "Nagaland", "Orissa",
     "Punjab", "Rajasthan", "Sikkim","Tamil Nadu", "Tripura", "Uttar Pradesh",
     "Uttarakhand", "West Bengal"};
      String[] capitals = {"Hydrabad", "Itanagar", "Dispur","Patna", "Raipur",
      "Panaji", "Gandhinagar","Chandigarh", "Shimla", "Srinagar", "Ranchi",
      "Bengaluru", "Thiruvananthapuram", "Bhopal","Mumbai","Imphal", "Shillong",
      "Aizawl", "Kohima", "Bhubaneswar", "Chandigarh","Jaipur", "Gangtok", 
      "Chennai", "Agartala","Lucknow", "Dehradun", "Kolkata"}; 
      for(int i=0;i

	


          








					






       











		

Ads