Java Reference
In-Depth Information
program that prompts the user to enter the number n and the array of characters,
as shown in the sample output, and checks if the input array is a Latin square.
The characters are the first n characters starting from A .
Enter number n: 4
Enter 4 rows of letters separated by spaces:
A B C D
B A D C
C D B A
D C A B
The input array is a Latin square
Enter number n: 3
Enter 3 rows of letters separated by spaces:
A F D
Wrong input: the letters must be from A to C
**8.37
( Guess the capitals ) Write a program that repeatedly prompts the user to enter
a capital for a state. Upon receiving the user input, the program reports whether
the answer is correct. Assume that 50 states and their capitals are stored in a two-
dimensional array, as shown in FigureĀ 8.10. The program prompts the user to
answer all states' capitals and displays the total correct count. The user's answer
is not case-sensitive.
Alabama
Alaska
Arizona
...
...
Montgomery
Juneau
Phoenix
...
...
F IGURE 8.10
A two-dimensional array stores states and their capitals.
Here is a sample run:
What is the capital of Alabama? Montogomery
The correct answer should be Montgomery
What is the capital of Alaska? Juneau
Your answer is correct
What is the capital of Arizona? ...
...
The correct count is 35
 
 
Search WWH ::




Custom Search