Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
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
None
using python language
Using the piece of code on the previous slide, modify the code removing the x += 1 portion and run the code.
What happens?
Now modify the code to print the numbers but in reverse order
Lastly, modify the code to print the numbers 1 through 10 which are not divisible by 3
Subje ct: $ Comp. Graphics
Q. Rotate the following slope
about x- axis by A then translete
it to the first octaut & reflect it back
to onginel prsition
17,,9)
(-2,-2, 1)
A
(9,1,7)
Chapter 18 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th 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
- Write code that uses turtle graphics to draw an equilateral triangle, a square and a regular pentagon, each with side length 100.arrow_forwardWhat would you do if you want to erase recently drawn straight segments?arrow_forwardQ3: Lecture Hall Dan holds his CSC108 lectures in a rectangular N X M lecture hall. In other words, this lecture hall has N rows of seats, each of them containing exactly M seats. Here's my attempt at drawing this layout when N = 3 and M = 5: Dan Off 00 lecture hall layout with 3 rows and 5 seats per row The rows are numbered from 1 to N starting from the front row. Similarly, the columns are numbered from 1 to M starting from the leftmost column. We write (r, c) to denote the c-th seat in the r-th row. When Dan walks into the lecture hall this morning, some of the seats are already taken (this is the initial layout of the lecture hall). After that, the students come in one group at a time. From experience, Dan knows that when a group of K students enter the lecture hall, they look for K consecutive empty seats. That is, they try to find an empty seat (r, c) such that for all integers i in [0, K-1], the seat (r, c + 1) exists and is empty. If they can't find K consecutive empty seats,…arrow_forward
- This code segment find the Perimeter and area of any triangular using the equation formula as shown below. The values of a, b, and c are entered into separate text boxes and display Perimeter and area in separate text boxes. P=a+b+c: s= (a+b+c)/2: AR-√√s*(s-a)*(s-b)*(s-c) 1-..... 2-..... 3- P=a+b+c s=(a+b+c)/2 AR-Sqr(s* (s-a) * (s-b)* (s-c)) 4- 5- 1-a =inputbox("a") 2-b =inputbox("b") 3-c =inputbox("c") 4- T4.Text = P 5-T5.Text = AR 1-a = CInt(T1.Text) 2-b = Cint(T2.Text) 3-c = Cint(T3.Text) 4- P=T4. Text 5-AR=T5.Text 1- Cint(T1.Text) =a 2- O Cint(T2.Text)=b 3-Cint(T3.Text)=c 4-T4.Text = P 5-T5.Text = AR 1-a T1.Text 2-b = T2.Text 3-c = T3. Text 4-T4.Text = P 5-T5.Text = ARarrow_forwardi need same link design and code and output please curve and i need to input the Coordinates https://www.codeproject.com/Articles/5267642/A-Simple-Utility-for-Drawing-Function-Curvesarrow_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
- Try to modify the shape and code, and discover your plantChange the colorchange the petal numberchange the petal shapeput a leaf right next to the new flower (leaf shape is not important)Pick a different colour for the flower with different tones code n=800;r=linspace(0,1,n);theta=linspace(0,2*pi,n);[R,THETA]=ndgrid(r,theta);petalNum=5;x = 1 - (1/2)*((5/4)*(1 - mod(petalNum*THETA, 2*pi)/pi).^2 - 1/4).^2;phi = (pi/2)*exp(-2*pi/(8*pi));y = 1.95653*(R.^2).*(1.27689*R - 1).^2.*sin(phi);R2 = x.*(R.*sin(phi) + y.*cos(phi));X=R2.*sin(THETA);Y=R2.*cos(THETA);Z=x.*(R.*cos(phi)-y.*sin(phi));mapSize=20;blue_map=linspace(138,75,mapSize)';blue_map(:,2)=linspace(43,0,mapSize)';blue_map(:,3)=linspace(226,130,mapSize)';gold_map=[255 215 0; 250 210 0];violet_map=[gold_map; blue_map];surf(X,Y,Z,'LineStyle','none')colormap(violet_map/255)view([-12.700 81.200])arrow_forwardThis is everything that the question provides. There isn't anything else I can add to make the question more cleararrow_forwardUse Python to draw the pattern in the picture.arrow_forward
- Please help me create the below image ( Sue rpenski triangle) using java and recursion. Please comment each line of codearrow_forwardcode to create the product for each row, which we call a “score”. If acell is not filled in, we assume that its value is 1, so that multiplying it has a neutraleffect (any number multiplied by 1 is the number itself). Or, as in the code below, justdo not multiply the value of that cell at all.arrow_forwardI hope the solution is to use Visual Basicarrow_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