-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAll States of India.java
More file actions
76 lines (72 loc) · 2.83 KB
/
All States of India.java
File metadata and controls
76 lines (72 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package All_Sates;
/*
A basic program to show all states of India
and a simple function to check every Capital of each states as well
*/
import java.util.Arrays;
import java.util.Scanner;
public class States {
public static int getInfo(String stateinfo[][],String state){
int position=-1;
Boolean flag=false;
for(int i=0;i<stateinfo.length&&!flag;i++){
if(stateinfo[i][0].equalsIgnoreCase(state))
position=i;
}
return position;
}
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("\n\n\t\tName of India's all Sates :");
System.out.println("\t\t---------------------------\n");
String[][]StateInfo=new String[][]{
{"Andra Pradesh", "Hyderabad"},
{"Arunachal Pradesh", "Itangar"},
{"Assam", "Dispur"},
{"Bihar", "Patna"},
{"Chhattisgarh", "Rajpur"},
{"Goa", "Panaji"},
{"Gujrat", "Gandhinagar"},
{"Haryana", "Chandigarh"},
{"Himachal Pradesh", "Shimla"},
{"Jammu and Kashmir", "Srinagar and Jammu"},
{"Jharkhand", "Ranchi"},
{"Karnataka", "Banglore"},
{"Kerala", "Thiruvananthapuram"},
{"Madya Pradesh", "Bhupal"},
{"Maharashtra","Mumbai"},
{"Manipur","Imphal"},
{"Meghalaya","Shillong"},
{"Mizoram","Aizawi"},
{"Nagaland","Kohima"},
{"Orissa","Bhubaneshwar"},
{"Punjab","Chandigarh"},
{"Rajasthan","Jaipur"},
{"Sikkim","Gangtok"},
{"Tamil Nadu","Chennai"},
{"Tripura","Agartala"},
{"Uttaranchal","Dehradun"},
{"Uttar Pradesh","Lucknow"},
{"West Bengal","Kolkata"},
};
for(int i=0;i<StateInfo.length;i++){//prints all the states
System.out.println("\t"+(i+1)+". "+StateInfo[i][0]);
}
while (true){
System.out.println("\n* Type a state name to know about Capital or No to exit ");
System.out.print(" : ");
String input=sc.nextLine();
if(input.equalsIgnoreCase("NO")){
System.exit(0);
}else {
int position=getInfo(StateInfo,input);
if(position!=-1){
System.out.println("\n\tState : "+StateInfo[position][0]);
System.out.println("\tCapital : "+StateInfo[position][1]);
}else {
System.out.print("\r[Invalid state entered]\r");
}
}
}
}
}