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"); } } }
0 comments:
Post a Comment