多线程写时钟
package com.test;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Thread1 extends Thread{
SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss");
@Override
public void run() {
while (true){
try {
System.out.println(sdf.format(new Date()));
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
package com.test;
public class Main {
public static void main(String[] args) {
Thread1 thread1= new Thread1();
thread1.start();
}
}