Repeat Letters java contains an incomplete program whose goa

Repeat Letters java contains an incomplete program, whose goal is to take as input text from the user, and then print out that text so that each letter of the text is repeated multiple times Complete that program, by defining a repeat function, that satisfies the following specs: repeat Letters takes two arguments, called text, times. The function goes through the letters of text in the order in which they appear in text, and prints each such letter as many times as specified by the argument times. IMPORTANT: you are NOT allowed to modify in any way the main function. This is an example run of the complete program: Enter some text, or q to quit: hello Enter number of times (must be > 0:3) hhheeellllllooo Enter some text, or q to quit: good morning Enter number of times (must be > 0): 2 ggoooodd mmoorrnniinngg Enter some text, or q to quit: a b Enter number of times (must be > 0): 7 aaaaaaa bbbbbbb Enter some text, or q to quit: q Exiting...

Solution

Please find my program.

Please let me know in case of any issue.

import java.util.Scanner;

public class RepeatLetters{

  

// function defination

   public static void repeatLetters(String text, int times){

      

       // iterating through each character of test

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

          

           // printing current letters

           for(int j=1; j<=times; j++)

               System.out.print(text.charAt(i));

          

       }

       System.out.println(\"\ \");

   }

  

   public static void main(String[] args) {

      

       Scanner sc = new Scanner(System.in);

      

       String input = \"\";

       int times;

       while(true){

           System.out.print(\"Enter some test, or q to quit: \");

           input = sc.nextLine();

          

           if(input.equals(\"q\"))

               break; // stopping

          

           System.out.print(\"Enter number of times (must be > 0): \");

           times = sc.nextInt();

          

           // calling functuion

           repeatLetters(input, times);

       }

   }

  

}

/*

Sample output:

Enter some test, or q to quit: Hello

Enter number of times (must be > 0): 3

HHHeeellllllooo

Enter some test, or q to quit:q

*/

 Repeat Letters java contains an incomplete program, whose goal is to take as input text from the user, and then print out that text so that each letter of the
 Repeat Letters java contains an incomplete program, whose goal is to take as input text from the user, and then print out that text so that each letter of the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site