这是代码 -
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);
}
}
}
}
因此,我不想让控制台按照我在字符串中键入它们的顺序询问每个大写字母是什么,而是希望随机化它们被询问的顺序,并且我想将每次运行限制为五个问题。我有点迷失了这个。谢谢。