Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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. A text file (.txt) containing the outputs for n=8 and 16. You may run your program twice and concatenate the output to a single file.

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

Statistical And Scientific Database Management International Working Conference Ssdbm Rome Italy June 21 23 1988 Proceedings Lncs 339

Authors: Maurizio Rafanelli ,John C. Klensin ,Per Svensson

1st Edition

354050575X, 978-3540505754

More Books

Students also viewed these Databases questions

Question

Discuss the history of intelligence testing.

Answered: 1 week ago

Question

25.0 m C B A 52.0 m 65.0 m

Answered: 1 week ago

Question

Discuss five types of employee training.

Answered: 1 week ago

Question

Identify the four federally mandated employee benefits.

Answered: 1 week ago