This is the Problem with Java Programming. Please solve the Problem with recursi
ID: 3749539 • Letter: T
Question
This is the Problem with Java Programming. Please solve the Problem with recursion and as directed in the question.
thanks
Exercise 18.9: (Print the characters in a string reversely) Write a recursive method that displays a string reversely on the console using the the following header: public static void reverseDisplay(String value) For example, reverseDisplay("abcd") displays dcba. Write a test program that prompts the user to enter a string and displays its reversal. Exercise 18.12: Rewrite Programming Exercise 18.9 using a helper method to pass the substring high index to the method. The helper method is: public static void reverseDisplay(String value, int high)Explanation / Answer
18.9) import java.util.Scanner; public class ReverseDisplay { public static void reverseDisplay(String value) { if(value.length() != 0) { reverseDisplay(value.substring(1)); System.out.print(value.charAt(0)); } } public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter a string: "); String line = in.nextLine(); reverseDisplay(line); System.out.println(); } } 18.12) import java.util.Scanner; public class ReverseDisplay { public static void reverseDisplay(String value) { reverseDisplay(value, value.length()-1); } public static void reverseDisplay(String value, int high) { if(high >= 0) { System.out.print(value.charAt(high)); reverseDisplay(value, high-1); } } public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter a string: "); String line = in.nextLine(); reverseDisplay(line); System.out.println(); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.