-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram20.java
34 lines (28 loc) · 1004 Bytes
/
Program20.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
/* Program 20
Write a program to enter 10 countries and capitals into two single dimensional arrays. Enter the value of a country and print its corresponding capital.
12/02/24
*/
import java.util.Scanner;
public class Program20 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String countries[] = new String[10], country;
String capitals[] = new String[10];
int i;
boolean flag = false;
for (i = 0; i < 10; i++) {
System.out.print("Enter a country: ");
countries[i] = sc.next();
System.out.print("Enter its capital: ");
capitals[i] = sc.next();
}
System.out.print("Enter the country to search for: ");
country = sc.next();
for (i = 0; i < 10; i++)
if (countries[i].equals(country)) {
flag = true;
break;
}
System.out.println(flag ? "Capital: " + capitals[i] : "Invalid country");
}
}