Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 18.8, Problem 18.8.5CP
Program Plan Intro
Recursive method:
A method which is called again and again by itself is called as recursive method. With the help of recursive method, it is possible to solve certain problems more quickly and easily.
Base case: The recursion method contains a base case which is used to halt the recursion.
Recursive call: When the function itself calls the same function is called as recursive call.
“displayTriangles ()” method:
- The “displayTriangles ()” method is used to display triangles by creating a triangle using “Polygon triangle = new Polygon ()” statement.
- This function get all the points using “getPoints ()” function.
- This method is a recursive method which contains base case and recursive call.
- In this method, the base case is present in the “if” statement.
- “if (order == 0)”
- In this method, the base case is present in the “if” statement.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Computer Science
IN PYTHON(visual studio code) program a simple flag that consists of at least two shapes while only using rectangles and circles. Give it a flagpole by drawing a long skinny rectangle next to it. Wave the flag by animating it up and down. (make the Swedish and UK flag)
import pgzero
What would you do if you want to erase recently drawn straight segments?
use java
Chapter 18 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 18.2 - What is a recursive method? What is an infinite...Ch. 18.2 - Prob. 18.2.2CPCh. 18.2 - Show the output of the following programs and...Ch. 18.2 - Prob. 18.2.4CPCh. 18.2 - Prob. 18.2.5CPCh. 18.2 - Write a recursive mathematical definition for...Ch. 18.3 - Prob. 18.3.1CPCh. 18.3 - What is wrong in the following methods?Ch. 18.3 - Prob. 18.3.3CPCh. 18.4 - Describe the characteristics of recursive methods.
Ch. 18.4 - Prob. 18.4.2CPCh. 18.4 - Prob. 18.4.3CPCh. 18.5 - Prob. 18.5.1CPCh. 18.5 - Prob. 18.5.2CPCh. 18.5 - What is a recursive helper method?Ch. 18.6 - Prob. 18.6.1CPCh. 18.6 - How does the program get all files and directories...Ch. 18.6 - How many times will the getSize method be invoked...Ch. 18.6 - Will the program work if the directory is empty...Ch. 18.6 - Will the program work if line 20 is replaced by...Ch. 18.6 - Will the program work if lines 20 and 21 are...Ch. 18.7 - Prob. 18.7.1CPCh. 18.8 - Prob. 18.8.1CPCh. 18.8 - Prob. 18.8.2CPCh. 18.8 - How many times is the displayTriangles method...Ch. 18.8 - Prob. 18.8.4CPCh. 18.8 - Prob. 18.8.5CPCh. 18.9 - Which of the following statements are true? a. Any...Ch. 18.9 - Prob. 18.9.2CPCh. 18.10 - Identify tail-recursive methods in this chapter.Ch. 18.10 - Rewrite the fib method in Listing 18.2 using tail...Ch. 18 - Prob. 18.1PECh. 18 - Prob. 18.2PECh. 18 - (Compute greatest common divisor using recursion)...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Fibonacci series) Modify Listing 18.2,...Ch. 18 - Prob. 18.8PECh. 18 - (Print the characters in a string reversely) Write...Ch. 18 - (Occurrences of a specified character in a string)...Ch. 18 - Prob. 18.11PECh. 18 - (Print the characters in a string reversely)...Ch. 18 - (Find the largest number in an array) Write a...Ch. 18 - (Find the number of uppercase letters in a string)...Ch. 18 - Prob. 18.15PECh. 18 - (Find the number of uppercase letters in an array)...Ch. 18 - (Occurrences of a specified character in an array)...Ch. 18 - (Tower of Hanoi) Modify Listing 18.8,...Ch. 18 - Prob. 18.19PECh. 18 - (Display circles) Write a Java program that...Ch. 18 - (Decimal to binary) Write a recursive method that...Ch. 18 - (Decimal to hex) Write a recursive method that...Ch. 18 - (Binary to decimal) Write a recursive method that...Ch. 18 - (Hex to decimal) Write a recursive method that...Ch. 18 - Prob. 18.25PECh. 18 - (Create a maze) Write a program that will find a...Ch. 18 - (Koch snowflake fractal) The text presented the...Ch. 18 - (Nonrecursive directory size) Rewrite Listing...Ch. 18 - (Number of files in a directory) Write a program...Ch. 18 - (Game: Knights Tour) The Knights Tour is an...Ch. 18 - (Game: Knights Tour animation) Write a program for...Ch. 18 - (Game: Eight Queens) The Eight Queens problem is...Ch. 18 - Prob. 18.35PECh. 18 - (Sierpinski triangle) Write a program that lets...Ch. 18 - (Hilbert curve) The Hilbert curve, first described...Ch. 18 - (Recursive tree) Write a program to display a...Ch. 18 - Prob. 18.39PE
Knowledge Booster
Similar questions
- use python codearrow_forwardPython code polygon, draw any polygon using Turtlesim in ROS2 Foxy – Python! Given the number of sides (n) and length of sides (l), one can easily draw anypolygon shape.arrow_forwardYou wrote a program to draw a line from (24, 154) to some point (a, b). Your program draws the line using 75 pixels. While drawing, NE and E points were chosen equal number of times [assume that (24, 154) is neither an NE nor an E point]. What is the value of b? (Hint: a = 98).arrow_forward
- Use python to create 1000 x 1000 random square matrix, and save it into a CSV file. Then, read the CSV file and compute the sum of squares of the diagonal elements.arrow_forwardUse python code with "def drawItem(img,item,row,col):" but without using cv2,PIL or numpy drawItem(canvas, item, row, col) - Modify canvas by drawing the non-white pixels of the item (intended to be the image of a word) onto canvas. Row and col represent the top left pixel of canvas where the item (the item's top left 0,0 pixel) should be placed. Canvas and item are 2D images of RGB pixels. This function should assume that the canvas image is large enough to contain the item img in the row col indicated; row and col do NOT need to be validated.arrow_forwardThis does not appear to be the answer to this question; Cheese's position is randomly generated in a 5x5 grid. The initial positions are x,y. The position of Cheese is not specified as (3, 4)arrow_forward
- Computer Science Write a program to find the image gradients of any gray scale image of your choice in python only. • Display the original, the gradient in x direction, the gradient in y direction, and the gradient magnitude images. • Apply a simple threshold to the gradient magnitude image and display the gradient magnitude and the thresholding image. You may use 100 as your threshold value or any other appropriate value.arrow_forwardPython code Upload a picture of your code(please don’t type it in here).arrow_forwardNeed in pythonarrow_forward
- Algorithm. Draw 10 "right" stars of the same size without taking hand from paperarrow_forwardA line has a starting point (9.18) and ending point (14,22). Apply the Bresenham's Line Drawing algorithm to plot a line.arrow_forwardCode with comments and output screenshot is must for an Upvote. Thank you!arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT