Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

 

(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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Heres an outline for each of these methods along with the recursive helper methods apublic class ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

8.5 What digital strategies do marketing professionals employ?

Answered: 1 week ago