比如说for(int i=0;i<5;i++) {
     System.out.println(i);
}这样就输出了:
0
1
2
3
4我希望改一下:for(int i=0;i<5;i++) {
     System.out.println(i);
      ...  //清除输出在控制台上显示的上一个数
}这样输出的时候就看见数字在变化但是始终是在一行,且只有一个数字,就好像电子表一样那种效果该使用哪个方法,在哪个包哪个类中???谢谢各位~

解决方案 »

  1.   

    public class Test {
    public static void main(String... a) {
    for(int i=0; i<100; i++) {
    System.out.print("\b" + i);
    try {
    Thread.sleep(1000);
    } catch (Exception e) {}
    }
    }
    }
      

  2.   

    import java.text.*;
    public class Test {
    public static void main(String... a) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    for(int i=0; i<100; i++) {
    System.out.print("\r当前时间:" + format.format(new java.util.Date()));
    try {
    Thread.sleep(1000);
    } catch (Exception e) {}
    }
    }
    }
    要在cmd中运行
      

  3.   

    Runtime.getRuntime().exec( "cmd   cls ");