クロスワードのような単語にマッチする単語を作って、単語や他のパズルゲームとJava Netbeansで一致させたいと思います。私は自分のint =私の配列に格納している言葉を作るのに問題があった。Javaで一致する単語
String word; int numword=0;
// Words that will be stores in my arry
String [] myNames = {"Pie","Soccer","Chelsea","Gaming","Steam"};
// User inputs the number
numword = new Scanner(System.in).nextInt();
// Print the word for testing purposes
System.out.println(myNames[numword]);
// Type the word
word = new Scanner(System.in).nextLine();
// Check if the word is right
if (word.equals(n)){
System.out.println("You got it");
}else{
System.out.println("You got it wrong");
}
は、なぜあなたは、新しいスキャナオブジェクトを毎回作成するのですか? 1つのオブジェクトを作成し、それを使用します。ここで 'n 'とは何ですか?これは 'myNames [numword]'でなければなりません。 – Li357
配列の長さよりも大きな数値を入力するとどうなりますか? –