Question: Write a recursive method called parenthesize that takes a String and an integer n as parameters and that prints the string inside n sets of
Write a recursive method called parenthesize that takes a String and an integer n as parameters and that prints the string inside n sets of parentheses. For example, this code:
parenthesizeJoe;
System.out.println; to complete line of output
parenthesizeThe University of Washington", ;
System.out.println; to complete line of output
parenthesizemidterm;
System.out.println; to complete line of output
should produce these lines of output:
Joe
The University of Washington
midterm
Your method should throw an IllegalArgumentException if passed a negative number. It could be passed as in:
parenthesizeCS Spring ;
System.out.println; to complete line of output
In this case the output would have no ie parentheses:
CS Spring
You are not allowed to construct any structured objects no array, ArrayList, String, StringBuilder, etc and you may not use a while loop, for loop, or dowhile loop to solve this problem; you must use recursion.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
