(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...
-
Consider two different products: an industrial product and a consumer product. How would the media for these products differ? What would affect the advertising scheduling for these two products?
-
In Problem construct a mathematical model in the form of a linear programming problem. (The answers in the back of the book for these application problems include the model.) Then solve the problem...
-
Why is it important to evaluate your change management experiences and document them as lessons learned? AppendixLO1
-
The state of Artexva advance refunded $8,000,000 par of 20X2, 10% serial bonds by issuing $9,000,000 par of 20Y6, 6% serial bonds. Required Prepare the entries required to record the following...
-
I need the step solution for 4 and 5. Thank you!! Use the information below to answer the following two questions: Chamomile Inc. is a manufacturing company whose total manufacturing overhead costs...
-
On January 1, 2020, K. Crew Inc. reported a $6,000 credit balance in its Accumulated OCIPension Gain/Loss account related to its pension plan. During 2020, the following events occurred. Actual...
-
chegg had all the wrong answers to these questions December 31". and the bonds mature on Decem Poky Pig Company issued $500,000 in bonds at face value on January 1, 2015. The contract (stated) rate...
-
FA II: Assignment 1 - COGS & Bank Reconciliation 1. The following data pertains to Home Office Company for the year ended December 31, 2020: Sales (25% were cash sales) during the year Cost of goods...
-
Bramble Stores accepts both its own and national credit cards. During the year, the following selected summary transactions occurred. Jan. 15 20 Feb. 10 15 Made Bramble credit card sales totaling...
-
11. Korina Company manufactures products S and T from a joint process. The sales value at split-off was P50000 for 6,000 units of Product S and P25,000 for 2,000 units of Product T. Assuming that the...
-
Karak Company produces Product (A) for only domestic distribution since year 2017. In 2019, a similar product to Karak Company has come onto the market by another competitor. Karak Company is keen to...
-
1. Purchase equipment in exchange for cash of $20,400. 2. Provide services to customers and receive cash of $4,900. 3. Pay the current month's rent of $1,000. 4. Purchase office supplies on account...
-
ework Saved O Required information The following information applies to the questions displayed below.) On January 1, 2021. Frontier World Issues $39.3 million of 7% bonds, due in 10 years, with...
-
Question 6.10 Current and deferred tax worksheets and tax entries From the hip Ltd?s statement of profit or loss for the year ended 30 June 2007 and extracts from its statements of financial position...
-
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...
-
What do these classes of ratios measure? (a) Liquidity ratios. (b) Profitability ratios. (c) Solvency ratios. AppendixLO1
-
(a) Ruth Weber believes that the analysis of finan- cial statements is directed at two characteristics of a company: liquidity and profitability. Is Ruth correct? Explain. (b) Are short-term...
-
Holding all other factors constant, indi- cate whether each of the following signals generally good or bad news about a company. (a) Increase in earnings per share. (b) Increase in the current ratio....
Study smarter with the SolutionInn App