2011-10-20 88 views
-3

可能重複:
Java String new line插入新行

我nobbish在java.how我插在與條件每10個字符換行它必須是一個空間?像

「我是男孩」

出來放應

新線每個字符串。

+0

如果上一個問題的答案對您沒有意義,那是因爲您的問題不清楚。您應該編輯上一個問題以使*更清晰。如果你只是提出一個新問題,它很可能會被重複關閉。 –

+0

'System.out.println(「I \ nam \ nboy」);' – fireshadow52

回答

1
class NewLiner { 
    public static void main(String[] args) { 

     String test = "0 2 4 6 8 10"; 

     char[] cs = test.toCharArray(); 
     int step = 10; 
     int count = (int) (cs.length/step); 
     int limit = count * step + 1; 

     for (int i = step - 1; i < limit; i+= step) { 
      if (Character.isWhitespace(cs[i])) { 
       cs[i] = '\n'; 
      } 
     } 

     System.out.println(new String(cs)); 

    } 
}