Write a method named stutter that accepts a string parameter returns a new string replacing each of its characters with two consecutive copies of that character. For example, a call of stutter("hello") would return "hheelllloo".

Respuesta :

Answer:

 public static String stutter(String a ) {

     String myText = "";

     for (int i = 0; i < a.length(); i++) {

           myText = myText + a.charAt(i) + a.charAt(i);

      }

    return myText;

 }

Explanation:

Programming language used: Java

public static String stutter(String a )

//Define a method stutter which is public  (accessible from outside of the class) and static(accessible without creating the object of its class) and with a string argument

String myText = "";

//Defines an empty string

 for (int i = 0; i < a.length(); i++) {

           myText = myText + a.charAt(i) + a.charAt(i);

      }

//loop through each character of the string and concatenate each character twice

 return myText;

//return the final string