-
Notifications
You must be signed in to change notification settings - Fork 0
/
YT10.java
57 lines (50 loc) · 1.85 KB
/
YT10.java
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
/*Write a program in Java to declare two single dimensional array of String type using static initialization and
*store the name of 10 indian states and their capitals as shown below:
*No. State Name Capital Name
*1 Andhra Pradesh Hyderabad
*2 Arunachal Pradesh Itanagar
*3 Assam Dispur
*4 Bihar Patna
*5 Chhatisgarh Raipur
*6 Goa Panaji
*7 Gujarat Gandhinagar
*8 Haryana Chandigarh
*9 Himachal Pradesh Shimla
*10 Jammu & Kashmir Srinagar
*Ask the user to enter a state & check whether the state is in the list or not.
*If present display the capital else display a message "State not found in the list"
*/
import java.io.*;
class YT10
{
public static void main(String[] args)throws IOException
{
String state[]={"Andhra", "Arunachal", "Assam", "Bihar", "Chhattisgarh", "Goa", "Gujarat", "Harayana", "Himachal", "J&K" };
String capital[]={"Hyderabad", "Itanagar", "Dispur", "Patna", "Raipur", "Panaji", "Gandhinagar", "Chandigarh", "Shimla", "Srinagar"};
String x;
int pos=0;
int l=state.length;
int flag=0;
InputStreamReader I = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(I);
System.out.println("Enter the state which you want to find: ");
x=br.readLine();
for(int i=0; i<l; i++)
{
if(x.equalsIgnoreCase(state[i]))
{
pos=i;
flag=1;
break;
}
}
if(flag==1)
{
System.out.println(capital[pos]);
}
else
{
System.out.println("NOT FOUND");
}
}
}