我是Java的新手,为了学习更多,我尝试制作一个时钟.它工作得很好,除了每次每秒更改时它都在新行上打印的事实.如何制作它以便我可以用新时间替换已经打印出来的文本?
public class test {
public static void main(String[] args) {
test.clock();
}
public static void clock() {
int sec = 0;
int min = 0;
int h = 0;
for(;;) {
sec++;
if(sec == 60) {
min++;
sec = 0;
} else if(min == 60) {
h++;
min = 0;
} else if(h == 24) {
h = 0;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(h < 10) {
System.out.print("0"+h+":");
} else {
System.out.print(h+":"); …Run Code Online (Sandbox Code Playgroud)