java
1import java.util.ArrayList; 2import java.util.Arrays; 3import java.util.Scanner; 4 5public class animal { 6 public static void main(String[] args) { 7 8 ArrayList<String> AppearanceHead = new ArrayList<String>(); 9 AppearanceHead = new ArrayList<>(Arrays.asList("kuma", "cat", "dog", "rabbit")); 10 11 ArrayList<Integer> LEVEL = new ArrayList<Integer>(); 12 LEVEL = new ArrayList<>(Arrays.asList(1, 2, 3, 4)); 13 System.out.println("1~3の数字を入力してください。"); 14 String selectLevel = ""; 15 int intSelectLevel = 0; 16 Scanner scanner = new Scanner(System.in); 17 selectLevel = scanner.nextLine(); 18 intSelectLevel = Integer.parseInt(selectLevel) - 1; 19 System.out.println("<" + LEVEL.get(intSelectLevel) + "モード>"); 20 int missCount = 3; 21 int Miss = 0; 22 int Nice = 0; 23 while (missCount != 0 || Nice >= 10) { 24 int targetIndex = (int) (Math.random() * AppearanceHead.size()); 25 System.out.println("| |" + AppearanceHead.get(targetIndex)); 26 System.out.println("aかbを入力してください"); 27 String UserOperation; 28 UserOperation = scanner.nextLine(); 29 Thread t = new Thread(); 30 t.start(); 31 32 } 33 34 } 35} 36 37class ThreadSample extends Thread { 38 public void run(int missCount , String UserOperation) { 39 try { 40 Thread.sleep(3 * 1000); 41 if (UserOperation == null) { 42 System.out.println("制限時間OVER"); 43 missCount--; 44 } 45 } catch (InterruptedException e) { 46 e.printStackTrace(); 47 } 48 49 } 50}
したいこと
時間制限の実装をしたいです。
コンソールで
System.out.println("aかbを入力してください");
String UserOperation;
UserOperation = scanner.nextLine();
class TimeCheckThread extends Thread {
}
あなたの回答
tips
プレビュー