2011-10-20 87 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)); 

    } 
}