Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

The Hailstone series is defined as follows: Start with any integer n strictly greater than 0. . If n is even, then the next value

image text in transcribed
image text in transcribed
The Hailstone series is defined as follows: Start with any integer n strictly greater than 0. . If n is even, then the next value in the series is n/2. . If n is odd, then the next value in the series is 3*n + 1. Repeat until you reach a value of 1 for the series. Below is a sample transcript of what your program should do. As always, entries in bold are use input and should not be put on the screen by your program. Enter a starting value: 19 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 A second run of the code might look like this: Enter a starting value: 18 18, 9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 on of T Y BUURMarks Window Help osu.instructure.com * YOUR DESCRIPTION OF THE CODE HERE * @author YOUR NAME HERE * @version DATE HERE import java.util.Scanner; public class Hailstone Series { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); // YOUR CODE HERE I keyboard.close(); NOTE: One of the surprisingly tricky things about the code above is making sure that the final number doesn't have a comma after it. You can't print something to the screen and then delete it after, so you have to make sure your code doesn't print that comma at all. How can you make sure that the final number doesn't have a comma after it. HINT: Keep in mind that your last value, by the definition given above, MUST be 1. on Next

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions