How to repeat each of the individual letters in a piece of text? in Java -


Number of times specified by the multiplier provided in a stutter, if the text was "Dean" and multiplier 3, the result would be "dddeeeaaannn " Will happen.

  public static zero repeatLetters () {string text = "dean"; Int n = 3; Stringbilder repeat = new stringbilder (text); For (int i = 0; i & lt; n; i ++) {repeat.append ("dean"); } System.out.println (text); }  

Not getting the required result Are you doing wrong?

You are just appending the letter n for every latitude you repeat through the string And have to add each character n times.

public static zero repeaters () {string text = "dean"; Int n = 3; Stringbinder repetition = new stringbiller (); For (int i = 0; i & lt; text.length (); i ++) {for (int j = 0; j & lt; n; j ++) {repeat.append (text.charAt (i )); }} System.out.println (repeat); }

In addition, another solution would be to use regular expressions.

  public static zero repeatLetters () {string text = "dean", replaced = ""; Int n = 3; For (int i = 0; i & lt; n; i ++) + = "$ 1" varies; System.out.println (text.replaceAll ("(.)", Replace)); }  

Comments

Popular posts from this blog

eclipse plugin - Run java code error: Workspace is closed -

ios - How do I use CFArrayRef in Swift? -

scala - Play Framework - how to bind form to a session field -