-4
我试图得到随机状态和首都的输出,但我的输出总是问“什么是阿拉巴马州的首府?然后显示下一行的错误。我怎样才能让它正确地询问赎金状态和资本?国家和资本猜测游戏并行数组
public static void main (String args [])throws FileNotFoundException {
Scanner input= null;
Scanner file=null;
try
{ input= new Scanner(System.in);
file= new Scanner (new File ("capitals.txt"));
while (file.hasNext()){
String[] myString = file.next().split (",");
System.out.println(String.format ("What is the capital of %s?", myString[0]));
System.out.println(input.next().equals(myString[1]));
}
}
catch (FileNotFoundException fe){
}
finally {
file.close();
input.close();
}
}
顺便说一句,我的进口和类是进口java.util.Scanner的; import java.io. *; import java.io.FileNotFoundException; public class StateCapitalLookup { –
哪里有随机数?您没有生成索引 –