197k views
1 vote
JAVA 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

1 Answer

3 votes

Answer:

Scanner sc= new Scanner(System.in);

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

String str = sc.nextLine();

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

int num = sc.nextInt();

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

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

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

}

}

Step-by-step explanation:

That should work just let me know!

User Rafa
by
5.8k points