-2

Possible Duplicate:
Java String new line

I am nobbish in java.how do I insert a newline at every 10 character with the condition it must be a space ? Like

"I am boy"

out put should be

New line every string.

Community
  • 1
  • 1
Md. Rashedul Hasan
  • 1,749
  • 2
  • 12
  • 8
  • If the answers to your previous question don't make sense to you, it is because your question wasn't clear. You should edit the previous question to *make it* more clear. If you simply ask a new question, it is likely to get closed as a duplicate. – Stephen C Oct 20 '11 at 09:57
  • `System.out.println("I\nam\nboy");` – fireshadow52 Oct 20 '11 at 10:26

1 Answers1

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));

    }
}
Saul
  • 17,973
  • 8
  • 64
  • 88