GUIで文字を使用して文字を比較する方法を知りたいだけです。文字をランダムにする方法は次のとおりです。
Random r = new Random();
char c = (char) (r.nextInt(26) + 'a');
次に、それを入力文字と比較したいときは、次のようにします。
char c;
if(x==c) {
prompt.setText("Correct!");
prompt.setForeground(Color.GREEN);
}
else if(x > c) {
prompt.setText("Oops! Letter is lower");
prompt.setForeground(Color.RED);
}
else if(x < c) {
prompt.setText("Oops! Letter is higher");
prompt.setForeground(Color.RED);
}
しかし、プログラムを実行するたびに、文字を入力するたびに、結果は「おっと! 文字が高い」という結果になります。
お願い助けて。このプログラムを正しく実行するには?
ありがとう!