Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        5年前关闭。
                    
                
        

我想知道我要在一个特定的时间间隔中一个接一个地打印字符串。

一切安好。

我想知道,当第二个字符串打印覆盖第一个字符串时,第三个字符串覆盖第二个字符串,依此类推。

我怎样才能做到这一点?

这是我的代码:

public class StringTest {

  public static void main(String args[]) {

    String arr[] = { "mahtab", "hussain", "yasir", "azmi", "saif" };

    int l = arr.length;

    for (int i = 0; i < arr.length; i++) {
      System.out.print(arr[i]);
      try {
        Thread.sleep(5 * 1000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
}

最佳答案

您可以使用回车符\r轻松完成此操作。

System.out.print(arr[i]+"\r")

关于java - 如何在java中一个接一个地打印字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25768495/

10-12 01:16
查看更多