Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given a positive integer num, the following rules will always create a sequence that ends with 1, called the hailstone sequence: If num is

Given a positive integer num, the following rules will always create a sequence that ends with 1, called the

Given a positive integer num, the following rules will always create a sequence that ends with 1, called the hailstone sequence: If num is even, divide it by 2 If num is odd, multiply it by 3 and add 1 (ie. 3*num +1) Continue until num is 1 Write a method, hailstone(), that takes in a positive integer as a parameter and prints the hailstone sequence starting with that integer. Format the output so that ten integers, each separated by a tab character (\t), are printed per line. Assume the input to the program is always positive. The output format can be achieved as follows: System.out.print (num + "\t"); Ex: If the program input is: 25 the output of method hailstone() is 25 34 8 Note: Your program must define the method: public void hailstone(int num) LAB ACTIVITY 5 6 7 8 9 18 1 2 3 H15 16 1 import java.util.Scanner; 2 3 public class Hailstone { 4 10 76 38 17 52 26 13 40 4 2 1 11 12 13 19 58 29 88 20 15} 6.18.1: LAB. Hailstone sequence (EO) /Type your code here. / 14 } 44 10 N 22 5 public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Hailstone labObject new Hailstone(); int num; 11 16 Hailstone.java 0/10 Load default template.... num scnr.nextInt(); labObject.hailstone(num); // Call hailstone() to print out the hailstone sequence.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Hailstonejava import javautilScanner public class Hailstone public void hailstonei... 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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Explain the regulation of the secretions of the small intestine.

Answered: 1 week ago