比如
有1,2,3,4,5
比如第一次出1,第二次输出2,第三次输出3,在同一个位置的

解决方案 »

  1.   

    这个...我在C语言里用过\bJava里没用过哦,你想做什么功能啊?
      

  2.   

    回车不换行  是  \rpublic static void main(String[] args) {
    // TODO 自动生成方法存根
    for(int i=1;i<=5;i++){
    System.out.print("\r");
    System.out.print(i);
    }
    }
      

  3.   

    楼主试试这个~很有意思~~不过只能在cmd下用~
    class Test {
    public static void main(String[] args)  {
    System.out.print("正在进行第 ");
    try {
    for( int i = 0; i < 10; i++) {
    System.out.print( "\b\b\b\b" +  i +  " 次");
    Thread.currentThread().sleep( 1000 );
    }
    }
    catch(Exception e) {
    System.out.println(e.toString());
    }
    }
    }
      

  4.   

    想实现在同一位置打印数字可以采用下面的方法,但是不能在Eclipse里面运行,这样不能看出效果。可在Windows的控制台中运行该类。
    public class Main {
        public static void main(String[] args) throws Exception {
            for(int i=1;i<=5;i++){
                System.out.print("\b");
                System.out.print(i);
                Thread.sleep(1000);
            }
        }
    }
      

  5.   

    确实只能在cmd看效果,不过还是觉得用 \r 合适,如果打印的不是单个字符而是字符串呢?
    看看下面这种情况:
    public class Test { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO 自动生成方法存根
    String []str={"asd","hello","home","office","edit"};
    for(int i=0;i<str.length;i++){
    System.out.print("\r");
    System.out.print(str[i]);
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    }
    }
    }}
      

  6.   

    怪不得了,我在EditPlus下用\b没效果,原来是有CMD下
      

  7.   

    public class Test {
        public static void main(String[] args) {
            for(int i=1;i<=5;i++){
       System.out.print("\r");
       System.out.print(i);
            }
        }
    }