Java: Program to Input Country Name And Print Capital

In this java tutorial we'll be "creating a java program which accepts a country name and prints its capital" .I'll be using arrays in this tutorials if you are unfamiliar with array head over to this tutorial. Now lets get started!!

import java.util.*;
class capital
{
    public static void main()
    {
        System.out.println("Test1");
        Scanner obj=new Scanner(System.in);
        String x[]={"India","Pakistan","Japan","Afghanistan"};
        String y[]={"New Delhi","Ismabad","Tokyo","Kabul"};
        System.out.print("Enter The Country Name");
        String in=obj.nextLine();
        int j=0;
       
        for(int i=0;i<=2;i++)
        {
           
            if(in.equalsIgnoreCase(x[i]))
            {
                System.out.println(y[i]);
                j=4;
                i=4;
            }
            
        }
        if(j<4)
        {
            System.out.println("This Country Not Available");
        }
   }
}
SHARE

Raunak Hajela

Hi. I’m CEO/Founder of Kodestat. I’m Student, Geek, Web Designer, Developer, Blog Enthusiast and Player. Inspired to make things looks better. I like playing with codes plus I am marvel fan :-P You can check my design portfolio here. For consulation fell free to drop an email at raunakhajela@gmail.com.

  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment