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

后端 未结 4 1289
悲&欢浪女
悲&欢浪女 2021-01-17 00:47

As in a stutter the number of times specified by the provided multiplier if the text was \"dean\" and the multiplier 3, the result would be \"ffffdeeeaaannn\".



        
4条回答
  •  情深已故
    2021-01-17 01:02

    You are simply appending the word "dean" to the end of your string three times.

    Try instead looping through each char in the word dean and appending that char three times.

    Something like this (this is pseudocode):

    StringBuilder repeat = new StringBuilder();
    
    ForEach( letter in "dean" )
        For( int i = 0 ; i < 3 ; i++ )
            repeat.add(letter);
    
    Return repeat
    

提交回复
热议问题