Write a method called printReverse that accepts a String as its parameter and prints the characters in opposite order. For example, a call of printReverse("hello there!"); should print the following output: !ereht olleh If the empty string is passed, no output is produced. Your method should produce a complete line of output.

Respuesta :

Answer:

//Method to reverse user text

public static void printReverse(String text) {

 //Create a variable to hold the reversed string

 //Initialize it to an empty string

 String reversedText = "";

 

 //Create a loop that cycles through each character in the text string

 //Prepend each character to the reversedText string

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

  reversedText = text.charAt(i) + reversedText;

 }

 

 //Display the reversed text

 System.out.println(reversedText);

 

}

Explanation:

Explanation has been given in the code in form of comments.

Hope this helps!