本人写了以下一段显示时间的代码,请问如何让时间刷新?我现在每次打println只是一行行打印出来.请问怎么样才能让它在原来的基础上刷新!
代码如下!
class time
{
int h;
int f;
int m;
String name;
String s;
public time(String name,int h,int f,int m)
{
this.name=name;
this.h=h;
this.f=f;
this.m=m;
}
public void runa()
{
do
{
 if(m==60)
 {
 m=0;
 f++;
 }
 if(f==60)
 {
 f=0;
 h++;
 }
 if(h==24)
 {
 h=0;
 }
 s=name+h+":"+f+":"+m;
 System.out.println(s);
 try
 {
 Thread.sleep(1000);
 }
 catch(Exception e)
 {
 System.out.print(e);
 }
 m++;
} while(h<24);   
}
}

解决方案 »

  1.   

    for (int i=0; i<s.length(); i++)
    System.out.print("\\x8");
    s = name + h + ":" + f + ":" + m;
    System.out.print(s);
      

  2.   

    我试过了,command line下可以。
      

  3.   

    dos命令行下是可以的。(java xxx.class)
      

  4.   

    if (s != null)
    for (int i=0; i<s.length(); i++)
    System.out.print((char)8);
      

  5.   

    System.out.print("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\");
      

  6.   

    class time implements Runnable或者继承Thread, 然后你实现一个run()方法...你写的runa()是什么意思?最后, 控制台如果用print和println输出太麻烦, 幸好Java5.0增加了printf方法, 类似C语言的printf函数, 不过功能更加强大...