저는 Java 초보자입니다. 3-4 시간 동안이 타이머 문제를 해결하려고 노력했습니다. 인터넷에서 거의 모든 것을 시도했습니다.Java Time Pause
중요한 것은 새로운 게임을 시작하거나 10 초를 기다리면 아무 것도 입력하지 않아도 메뉴로 리디렉션됩니다. 내 코드처럼 보이는 방법
이입니다
long startTime = System.currentTimeMillis();
long maxDurationInMilliseconds = 10000;
while (System.currentTimeMillis() < startTime + maxDurationInMilliseconds) {
Scanner end = new Scanner (System.in);
System.out.println("Enter anything if you want to start a new game or wait 10 seconds and you will be redirected to the Menu");
String value;
value = end.nextLine();
if (value != null) {
playGame();
}
else if (System.currentTimeMillis() > startTime + maxDurationInMilliseconds) {
// stop running early
showMainMenu();
break;
}
}
그러나
내가이 일을 얻을 수없는 어떤 이유로,이 작업을 얻기 위해 고투하고 유래 내 마지막 기회.편집 : 답장을 보내 주신 모든 분들께 감사드립니다. 아직 고쳐지지 않았고, 두통을 앓고 있으며 오전 3시 31 분입니다.
는'end.nextLine'은 차단 방법이다. 당신이 무언가를 입력 할 때까지는 무언가를 기다릴 것입니다. – MadProgrammer
브래킷이 없습니다. 배치는 어디입니까? –
멀티 스레딩 없이는이 작업을 수행 할 수 없습니다. – bstempi