私は、簡単な質問に時間制限付きの質問をするプログラムを書こうとしています。コンソール入力を待っている間にThread.sleep()を使ってタイマーを作る方法は?
これまでのところ、私は次のようしている:
public static void main(String[]args) throws IOException, InterruptedException{
Thread thread = new Thread();
Scanner scan = new Scanner(System.in);
System.out.println("1. What is 1+1?");
System.out.println("a. 2\tb. Cannot Be.\tc. 3\td. All of the above.");
String question1 = scan.next();
for(int i = 3; i>=0; i--){
System.out.print("\b"+i);
Thread.sleep(1000);
}
}
この適切に質問をし、答えがかかりますが、それは入力に時間制限をかけていないと後3から0 までカウントダウン入力が与えられる。私は間違って何をしていますか?
以下の答えは – developer