public static void main(String[] args)throws InterruptedException{
while(true){
for(int gre=15;gre>9;--gre){
Thread.sleep(1000);
System.out.printf("\r"+"绿灯:"+"%2d",gre);
}
for(int gre=9;gre>5;--gre){
Thread.sleep(1000);
System.out.printf("\r"+"绿灯:"+"%1d",gre);
}
for(int yel=5;yel>0;--yel){
Thread.sleep(1000);
System.out.printf("\r"+"黄灯:"+yel);
}
for(int red=15;red>0;--red){
Thread.sleep(1000);
System.out.printf("\r"+"红灯:"+red);
}
}
}
题目要求是15秒通行,有5秒是黄灯,15秒红灯
编译跟运行都没报错
目前出现的问题是绿灯打印10,下一个打印的却是90,然后80,间隔都是一秒,不知道这个零怎么去掉,
单独打印可以打印9.8.7,尝试分开也没有用
(初学者,基础有限,还望多多包涵)