ここにコードがあります -
import java.util.Scanner;
public class assn9 {
public static void main(String[] args){
String[][] stateCapital = {
{ "Alabama", "Montgomery" },
{ "Alaska", "Juneau" },
{ "Arizona", "Phoenix" },
{ "Arkansas", "Little Rock" },
{ "California", "Sacramento" },
{ "Colorado", "Denver" },
{ "Connecticut", "Hartford" },
{ "Delaware", "Dover" },
{ "Florida", "Tallahassee" },
{ "Georgia", "Atlanta" },
{ "Hawaii", "Honolulu" },
{ "Idaho", "Boise" },
{ "Illinois", "Springfield" },
{ "Indiana", "Indianapolis" },
{ "Iowa", "Des Moines" },
{ "Kansas", "Topeka" },
{ "Kentucky", "Frankfort" },
{ "Louisiana", "Baton Rouge" },
{ "Maine", "Augusta" },
{ "Maryland", "Annapolis" },
{ "Massachusettes", "Boston" },
{ "Michigan", "Lansing" },
{ "Minnesota", "Saint Paul" },
{ "Mississippi", "Jackson" },
{ "Missouri", "Jefferson City" },
{ "Montana", "Helena" },
{ "Nebraska", "Lincoln" },
{ "Nevada", "Carson City" },
{ "New Hampshire", "Concord" },
{ "New Jersey", "Trenton" },
{ "New York", "Albany" },
{ "New Mexico", "Santa Fe" },
{ "North Carolina", "Raleigh" },
{ "North Dakota", "Bismark" },
{ "Ohio", "Columbus" },
{ "Oklahoma", "Oklahoma City" },
{ "Oregon", "Salem" },
{ "Pennslyvania", "Harrisburg" },
{ "Rhode Island", "Providence" },
{ "South Carolina", "Columbia" },
{ "South Dakota", "Pierre" },
{ "Tennessee", "Nashville" },
{ "Texas", "Austin" },
{ "Utah", "Salt Lake City" },
{ "Vermont", "Montpelier" },
{ "Virginia", "Richmond" },
{ "Washington", "Olympia" },
{ "West Virginia", "Charleston" },
{ "Wisconsin", "Madison" },
{ "Wyoming", "Cheyenne" } };
int correctCount = 0;
for (int i = 0; i < stateCapital.length; i++)
{
System.out.println("What is the capital of " + stateCapital[i][0] + "?");
Scanner input = new Scanner(System.in);
String capital = input.next();
if (capital.equalsIgnoreCase(stateCapital[i][1])) {
correctCount++;
System.out.println("Your answer is correct, the correct count is " + correctCount);
}
else {
System.out.println("The correct answer should be " + stateCapital[i][1] + " and the correct count is " + correctCount);
}
}
}
}
そのため、コンソールに文字列に入力した順序で各大文字を尋ねる代わりに、質問される順序をランダム化し、各実行を 5 つの質問に制限したいと考えています。私はこれでちょっと迷っています。ありがとう。