(Recursion.java) Write a Java Program to implement the following recursive methods. Use the following main method....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
(Recursion.java) Write a Java Program to implement the following recursive methods. Use the following main method. Please note that the subproblems c and d are optional and have been included for additional practice. These will not be counted towards the lab grade. public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("************************* System.out.print("Enter an integer: "); int num = input.nextInt (); System.out.print("The reversal of " + num+" is "); reverseDisplay (num); System.out.println(); System.out.println("************* System.out.print("Enter a string: "); input.nextLine(); String str input.nextLine(); System.out.print("The reversal of " + str + " is "); reverseDisplay (str); System.out.println(); System.out.println("************* int[] list = new int[6]; System.out.print ("Enter 6 integers: "); for (int i = 0; i < 6; i++) list[i] = input.nextInt(); cube (list); System.out.println(); ************); System.out.println("************* System.out.print("The cubes of the elements are: "); for (int i = 0; i < 6; i++) System.out.print(list[i] + " "); System.out.print("Enter 5 integers: "); list new int[5]; for (int i = 0; i < list.length; i++) list[i] = input.nextInt (); **************); Strings input.nextLine(); char[] items=s.toCharArray(); *************"); System.out.println("The largest element is " + largest (list)); System.out.println("**************************************); System.out.print("Enter a string: "); input.nextLine(); System.out.print("Enter a character: "); char ch input.nextLine().trim().charAt(0); System.out.println(ch+ appears + count(items, ch) + " times"); Below is one sample run of the Program: ************ Enter an integer: 56784 The reversal of 56784 is 48765 Enter a string: Programming The reversal of Programming is gnimmargorP ******** Enter 6 integers: 1 2 3 The cubes of the elements are: 1 8 27 64 125 216 ***** ******* Enter 5 integers: 23 43 11 10 33 The largest element is 43 ******* Enter a string: Java Programming Enter a character: a a appears 3 times a. Print the digits in an integer reversely: Write a recursive method that displays an int value reversely on the console using the following header: public static void reverseDisplay(int value) • For example, reverseDisplay(12345) displays 54321. b. Print the characters in a string reversely: Write a recursive method that displays a string reversely on the console using the following header: public static void reverseDisplay(String value) ● For example, reverse Display("abcd") displays deba. c. [Optional] Print the cubes of numbers: Write a recursive method that cubes each element in an array. You need to define the following two methods. The second one is a recursive helper method. public static void cube(int[] list) public static void cube(int[] list, int low, int high) Use the method cube(int[] list, int low, int high) to cube the elements in list[low] to list[high]. d. [Optional] Find the largest number in an array: Write a recursive method that returns the largest integer in an array. You need to define the following two methods. The second one is a recursive helper method. public static int largest(int[] list) public static int largest(int[] list, int high) e. Occurrences of a specified character in an array: Write a recursive method that finds the number of occurrences of a specified character in an array. You need to define the following two methods. The second one is a recursive helper method. ● public static int count(char[] chars, char ch) public static int count(char[] chars, char ch, int high) Hand In: • Make a folder named lab9_yourname containing the source code file, zip the folder and submit the zipped file to BrightSpace. Rubrics: Program: • [2 marks] Presentation and Style: Readability, descriptive identifier, indentation, bracket placement, internal documentation (comments), use of appropriate constants, use of methods. [18 marks] Correctness: Program works without bugs (Recursion.java) Write a Java Program to implement the following recursive methods. Use the following main method. Please note that the subproblems c and d are optional and have been included for additional practice. These will not be counted towards the lab grade. public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("************************* System.out.print("Enter an integer: "); int num = input.nextInt (); System.out.print("The reversal of " + num+" is "); reverseDisplay (num); System.out.println(); System.out.println("************* System.out.print("Enter a string: "); input.nextLine(); String str input.nextLine(); System.out.print("The reversal of " + str + " is "); reverseDisplay (str); System.out.println(); System.out.println("************* int[] list = new int[6]; System.out.print ("Enter 6 integers: "); for (int i = 0; i < 6; i++) list[i] = input.nextInt(); cube (list); System.out.println(); ************); System.out.println("************* System.out.print("The cubes of the elements are: "); for (int i = 0; i < 6; i++) System.out.print(list[i] + " "); System.out.print("Enter 5 integers: "); list new int[5]; for (int i = 0; i < list.length; i++) list[i] = input.nextInt (); **************); Strings input.nextLine(); char[] items=s.toCharArray(); *************"); System.out.println("The largest element is " + largest (list)); System.out.println("**************************************); System.out.print("Enter a string: "); input.nextLine(); System.out.print("Enter a character: "); char ch input.nextLine().trim().charAt(0); System.out.println(ch+ appears + count(items, ch) + " times"); Below is one sample run of the Program: ************ Enter an integer: 56784 The reversal of 56784 is 48765 Enter a string: Programming The reversal of Programming is gnimmargorP ******** Enter 6 integers: 1 2 3 The cubes of the elements are: 1 8 27 64 125 216 ***** ******* Enter 5 integers: 23 43 11 10 33 The largest element is 43 ******* Enter a string: Java Programming Enter a character: a a appears 3 times a. Print the digits in an integer reversely: Write a recursive method that displays an int value reversely on the console using the following header: public static void reverseDisplay(int value) • For example, reverseDisplay(12345) displays 54321. b. Print the characters in a string reversely: Write a recursive method that displays a string reversely on the console using the following header: public static void reverseDisplay(String value) ● For example, reverse Display("abcd") displays deba. c. [Optional] Print the cubes of numbers: Write a recursive method that cubes each element in an array. You need to define the following two methods. The second one is a recursive helper method. public static void cube(int[] list) public static void cube(int[] list, int low, int high) Use the method cube(int[] list, int low, int high) to cube the elements in list[low] to list[high]. d. [Optional] Find the largest number in an array: Write a recursive method that returns the largest integer in an array. You need to define the following two methods. The second one is a recursive helper method. public static int largest(int[] list) public static int largest(int[] list, int high) e. Occurrences of a specified character in an array: Write a recursive method that finds the number of occurrences of a specified character in an array. You need to define the following two methods. The second one is a recursive helper method. ● public static int count(char[] chars, char ch) public static int count(char[] chars, char ch, int high) Hand In: • Make a folder named lab9_yourname containing the source code file, zip the folder and submit the zipped file to BrightSpace. Rubrics: Program: • [2 marks] Presentation and Style: Readability, descriptive identifier, indentation, bracket placement, internal documentation (comments), use of appropriate constants, use of methods. [18 marks] Correctness: Program works without bugs
Expert Answer:
Answer rating: 100% (QA)
Heres an outline for each of these methods along with the recursive helper methods apublic class ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
scratch or additional For the function f(x) shown below, graph gox)--fx+2)-2 on the same set of axes. -3 -2 - X = 0.9991- C) Express y(x) in factored form. 4 2 -2 4 -10 Consider the function...
-
A company pays its employees on a weekly basis. The employees are of four types: Salaried employees are paid a fixed weekly salary regardless of the number of hours worked, hourly employees are paid...
-
For this computer assignment, you are to write a C++ program to implement classes to represent a binary tree (of integers) . You are required to implement assignment5.h and assignment5.cc files. Both...
-
Arginine, the most basic of the 20 common amino acids, contains a guanidino functional group in its side chain. Explain, using resonance structures to show how the protonated guanidino group...
-
The SN2 reaction of (dihromomethyl) benzene, C6H5CHBr2, with NaOH yields benzaldehyde rather than (dihydroxymethyl) benzene, C6H5CH (0H)2 Explain.
-
Which of the following secondary alcohols can be prepared from the reaction of methyl formate with excess Grignard reagent? CH CH-CHCH CH CHCH CHCHCH,CH,CH CH3CH CHCH2CH3 OH OH
-
Explain how emissions trading schemes are likely to affect financial reporting.
-
Uphoff Company has $80,000 available to pay dividends. It has 2,000 shares of 10%, $100 par, preferred stock and 30,000 shares of $10 par common stock outstanding. The preferred stock is selling for...
-
n 1 1. lim tantan is equal to 004-1 1+r+r2 2. 3. If the least and the largest real values of a, for which the equation z + a |2-1+21=0(z=C and i=1) has a solution, are p and q respectively, then 4(p...
-
Right Company purchased 25,000 common shares (25%) of ON Inc. on January 1, Year 11, for $250,000. Right uses the equity method to report its investment in ON because it has significant influence in...
-
If merchandise costs $5,000, insurance in transit costs $250, duty costs $75, purchase order processing by purchasing department costs $25, and company receiving dock personnel cost $20, what is the...
-
The privilege of private necessity a. may be claimed only when the danger is severe. b. is a complete defense if the defendant causes no substantial harm to the plaintiffs property. c. can be invoked...
-
True Or False The concepts and terms used in tort law do not always correspond to those used in criminal law.
-
True Or False To commit battery the defendant must actually touch the plaintiff with their body.
-
True Or False The intent to commit one tort cannot be transferred to the tort that is actually committed.
-
True Or False Battery must involve contact with the plaintiffs body, not with something attached to the body.
-
A combination hepatitis A/typhoid (ViCPS) vaccine, administered as a single dose, confers high levels of protection against both these diseases. It will provide at least 6 month protection against...
-
What is the back work ratio? What are typical back work ratio values for gas-turbine engines?
-
Deborah purchases a new $30,000 car in 2012 to use exclusively in her business. If Deborah does not elect to expense or take bonus depreciation in 2012 and holds the car until it is fully...
-
Amy is a calendar-year taxpayer reporting on the cash basis. Please indicate how she should treat the following items for 2012: a. She makes a deductible contribution to an IRA on April 15,...
-
Leslie and Leon Lazo are married and file a joint return for 2012. Leslie's Social Security number is 466-47-3311 and Leon's is 467-74-4451. They live at 143 Snapdragon Drive, Reno, NV 82102. For...
-
Suppose a species of bacteria divides once every 20 minutes. You start with a single bacterium on your unrefrigerated egg-and-baloney sandwich at 8:00 am. Show that when you sit down to lunch at...
-
If two species belong to the same order, do they have to belong to the same class? Do they have to belong to the same genus?
-
The lightest and heaviest flying birds are the bee hummingbird of Cuba, which weighs about 1.6 grams, and the great bustard of Europe and Asia, which can weigh as much as 21 kilograms. Show that the...
Study smarter with the SolutionInn App