下面是我的代碼...我試圖讓一個倒數計時器。現在它正確地按照正確的順序倒計時。我試圖找出如何將代碼中的if語句,以便爲打印1分'秒,而不是1分'秒的Java如果/ for循環幫助
import java.util.Scanner;
public class countdown {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int minutes;
System.out.println("Please enter the timer countdown in minutes:");
minutes = scan.nextInt();
while (minutes < 1) {
System.out.print("Invalid entry: Enter 1 or more minutes: ");
minutes = scan.nextInt();
}
for (int i = minutes - 1; i >= 0; i--)
{
for (int s = 59; s >= 1; s--)
System.out.println(i + " minutes, " + s + " seconds");
System.out.println("The timer is done!");
}
}
}
這絕對作品爲我== 1分鐘,但我要如何合併的S == 1秒,而不是秒? – user3455588
我試了下面,它只糾正了0秒,1秒的問題.. – user3455588
@ user3455588我編輯了答案。 – leigero