Discover how IDNLearn.com can help you find the answers you need quickly and easily. Join our knowledgeable community and access a wealth of reliable answers to your most pressing questions.

Write code that takes a user input of a string and an integer. The code should print each letter of the string the n number of times, where n is the integer input from the user.

Sagot :

We will use Java to write the code with utility class is Scanner.

What is scanner in Java?

Scanner is class from util package in Java for read input in Java language. So the code is,

import java.util.Scanner;

public class Main {

   public static void main(String[] args) {

       // scanner object to take user inputs

       Scanner sc = new Scanner(System.in);

       // asking the user to input string value

       System.out.println("Input a String:");

       String str = sc.nextLine();

       // asking the user to input int value

       System.out.println("Input an integer:");

       int num = sc.nextInt();

       // loop for getting each char

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

           char Char = str.charAt(i);

           // loop for n times of current char

           for (int j = 0; j < num; j++) {

               System.out.print(Char);

           }

       }

       System.out.println();

   }

}

Learn more about Java here:

brainly.com/question/26642771

#SPJ4