Q1.
曜日を表示して、その英語表現を入力させる英単語プログラムを作成せよ。
●出題する曜日は乱数で生成する。
●学習者が望む限り、何度でも繰り返せる
[実行例]
英語の曜日名を小文字で入力してください。
金曜日:fryday [エンター]
違います(friday)。続ける? 1…Yes/0…No>1 [エンター]
火曜日:tuesday [エンター]
正解です。続ける? 1…Yes/0…No>1 [エンター]
水曜日:wednesday [エンター]
正解です。続ける? 1…Yes/0…No>0 [エンター]
アプリケーションを終了します。
[解答例]
public class Jn29{
public static void main(String[] args){
String[] weekJ={"日","月","火","水","木","金","土",};
String[] weekE={"sunday","monday","tuesday","wednesday","thursday","friday","saturday",};
System.out.println("英語の曜日名を小文字で入力してください。");
int select;
do{
int index=new java.util.Random().nextInt(weekJ.length);
System.out.print(weekJ[index]+"曜日:");
String ans=new java.util.Scanner(System.in).next();
String msg;
if(ans.equals(weekE[index])){
msg="正解です。";
}else{
msg="違います("+ weekE[index]+ ")。";
}
System.out.print(msg+"続ける? 1...Yes/0...No>");
select=new java.util.Scanner(System.in).nextInt();
}while(select == 1);
System.out.println("アプリケーションを終了します。");
}
}
コメント