Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

home / study / engineering / computer science / computer science questions and answers / question 1: write a complete recursive java program to compute

home / study / engineering / computer science / computer science questions and answers / question 1: write a complete recursive java program to compute the heights of the tick marks ...

Question: Question 1: Write a complete recursive java program to compute the heights of the tick marks on a...

Question 1:

Write a complete recursive java program to compute the heights of the tick marks on a ruler. Assume that the length of the ruler is a power of 2 (say n=2m, where m >=1) , and the marks are to be placed at every point between 0 and 2m, not including the endpoints. The endpoints 0 and 2m will have height 0. Here are the rules for computing the heights of the ticks for a ruler of length n=2m:

The middle point of the ruler has height log(n), where the logarithm is base 2. Stop if n <= 2.

Break the ruler into two equal halves of length n/2 each and set n=n/2

Repeat step 1 for both halves resulting from step 2.

You may use an array of the appropriate size to hold the heights. When printing your output, print the heights on one line, and the position of the points below. For the printing of the positions of the points, just print the last digit of the position. Here is an example for input value n=8. 012131210 012345678 Here is an example for input value n=16. 01213121412131210 01234567890123456 Your program should prompt the user for an integer (using a dialog box), check to make sure the length entered by the user is a power of 2 and at least 2. To check if a number is a power of 2, you need the Math.log and Math.round methods. Be careful that the Math.log routine in Java is base e (not base 2). You will need to do the appropriate conversion between base 2 and base e. Finally, your program should print the heights of the ruler's points as illustrated above.

text.txt

n=8

n=16

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Postgresql 16 Administration Cookbook Solve Real World Database Administration Challenges With 180+ Practical Recipes And Best Practices

Authors: Gianni Ciolli ,Boriss Mejias ,Jimmy Angelakos ,Vibhor Kumar ,Simon Riggs

1st Edition

1835460585, 978-1835460580

More Books

Students also viewed these Databases questions

Question

3. Write down the concept of learning curve from single unit data.

Answered: 1 week ago