Home Tutorial Java Core Find Capital using Switch-Case statement

 
 

Share on Google+Share on Google+
Find Capital using Switch-Case statement
Posted on: November 10, 2009 at 12:00 AM
Advertisement
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







					
					
Advertisement

Related Tags for Find Capital using Switch-Case statement:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 10, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com