Write code which takes a user input of a String and an integer. The code should print each letter of the String the number of times the user inputted in reverse order.

Sample run:

Input a String:
code
Input an integer:
3
eeedddoooccc


Note: Write In Java
Thank You...

Respuesta :

import java.util.Scanner;

public class JavaApplication70 {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

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

       String txt = scan.nextLine();

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

       int num = scan.nextInt();

       String newTxt = "";

       int w = 0;

       for (int i = txt.length()-1; i >= 0; i--){

           char c = txt.charAt(i);

           while (w < num){

               newTxt += c;

               w++;

           }

           w = 0;

       }

       System.out.println(newTxt);

   }

   

}

I hope this helps!

Following are the java program to input string:

Program Explanation:

  • Import package.
  • Defining a class Main.
  • Inside the class, the main method is defined.
  • Inside the main method two String variable "val, next", and three integer variable "n,x, j" is defined.
  • In the next step, a scanner class object is declared that inputs string and integer variable value.
  • After input value a loop is defined that holds a sting value and define a while loop that seprate the value and calculate its value and print its value.    

Program:

import java.util.*;//import package

public class Main //defining a class Main

{

  public static void main(String[] ar)//defining a main method  

  {

      String val,next="";//defining a String variable

      int n,x=0,j;//defining an integer variable

      Scanner bd = new Scanner(System.in);//defining a Scanner class object to input value

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

       val= bd.nextLine();//input String value  

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

      n = bd.nextInt();//input integer value

      for (j = val.length()-1; j >= 0; j--)//defining a for loop that calculate a value

      {

          char c = val.charAt(j);//defining a char variable that holds character value of string

          while (x < n)//defining loop for compare value

          {

              next += c;//incrementing the character value  

              x++;//incrementing integer value

          }

          x = 0;

      }

      System.out.println(next);//print value

  }

}

Output:

Please find the attached file.

Learn more:

brainly.com/question/18844825

Ver imagen codiepienagoya