java倒计时
提示用户输入秒数,每过一秒显示一条消息。直接时间用完例如:Enterthenumberofsecond:4enter4secondsremaining3secondsre...
提示用户输入秒数,每过一秒显示一条消息。直接时间用完
例如:
Enter the number of second: 4 enter
4 seconds remaining
3 seconds remaining
2 seconds remaining
1 second remaining
Stopped 展开
例如:
Enter the number of second: 4 enter
4 seconds remaining
3 seconds remaining
2 seconds remaining
1 second remaining
Stopped 展开
1个回答
展开全部
import java.util.*;
class MyTimer
{
public static void main(String[]args)throws Exception{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of second:");
int n=sc.nextInt();
for(int i=n;i>0;i--){
System.out.println(i+" seconds remaining");
Thread.sleep(1000);
}System.out.println("Stopped");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询