-7

为什么我在此代码中收到错误,请帮助我。错误来了

找不到符号thread.sleep

这是代码:

  import java.util.Date;
  class Date_Time
    {
      public static void main(String[] args)
      throws Throwable
     {
          while(true)
          {
             Date_Time d= new Date_Time();
             System.out.print(d);
             thread.sleep(500);
             System.out.println("\r");
             thread.sleep(500);
          }
      }
    }
4

2 回答 2

0

d是 a class,所以如果你打印一个类,你会得到它的 tostring 表示,所以修改这个类,(覆盖 toString 方法并从它返回你需要的)

import java.util.Date;
class Date_Time{
    public static void main(String[] args) throws Throwable {
        while(true){
            Date_Time d= new Date_Time();
            System.out.print(new Date());
            thread.sleep(500);
            System.out.println("\r");
            thread.sleep(500);
        }
    }
}
于 2016-01-30T10:49:44.850 回答
0

在 Java 中,它是Thread.sleep(500);大写字母。

编辑

Date_Time是你的课。如果要打印需要使用Date库的日期

Date d = new Date();
System.out.print(d);
于 2016-01-30T10:38:23.490 回答