Given a positive integer num, the following rules will always create a sequence that ends with...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
Hailstonejava import javautilScanner public class Hailstone public void hailstonei... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Develop a model for a document management system for a domain of your choosing including the model for a metadata repository and link to unstructured document store.
-
1. When designing a PCB card Cage assembly with a Cpk of 1.XY (For X, Y use your last two-digit UML ID). a. What is the recommended height of the PCB; given the tolerances below for WC and...
-
Hailstone sequence (due 28 feb 2015) take any natural number n. if n is even, divide it by 2 to get n // 2. if n is odd, multiply by 3 and add 1 to obtain 3 * n + 1. repeat the process indefinitely....
-
Suppose that a typical taxpayer has a marginal personal income tax rate of 35 percent. The nominal interest rate is 13 percent, and the expected inflation rate is 8 percent. a. What is the real...
-
Trip to Mars you are wailing on a project with NASA to launch a rocket to Mars, with the rocket blasting off from earth when earth and Mars are aligned along a straight line from the sun. If Mars is...
-
Convert each decimal number to binary. 18
-
A swaption is an option to enter a swap arrangement in the future. Suppose that company B has a debt of \(\$ 10\) million financed over 6 years at a fixed rate of interest of \(8.64 \%\). Company A...
-
Absorption costing and production volume variance -- alternative capacity bases Earths Best Light (EBL), a producer of energy-efficient light bulbs, expects that demand will increase markedly over...
-
Turner Company owns 15% of the outstanding stock of ICA Company. During the current year, ICA paid a $4.70 million cash dividend on its common shares. Ignore income taxes. What effect did this...
-
David is age 40 and was widowed in 2022. He has a daughter, Linda, age 8.David provided the entire cost of maintaining the household and over half of the support for Linda. In order to work, he pays...
-
John works as a waiter in a restaurant for 5 years under a contract of employment and he is paid 500 per week. Recently, one of his colleagues has told Jane, who is the manager and owner of the...
-
Generational issues (at least 3-4 pgs): What role are generational differences playing in the great resignation? Specifically, are there different rates of retention across generations within the...
-
Alignment of HR practices with company mission (3-4pgs): How well is Bank of America's compensation packages tied to performance management practices? Specifically, to what extent is Bank of...
-
HR Metrics (3-4 pgs with in-text citations (3-4) please): How are employers measuring the effectiveness of their retention strategies? In addition to actual retention statistics and comparison to...
-
You are the Manager for a local 24 hour pharmacy store. You hired Maria about two months ago as the Night Shift Lead. Overall her performance has been good. She has a good manner with customers, and...
-
Labor Unions answer the following questions: What are the advantages and disadvantages of labor unions? Are unions more popular or less popular now than they have been historically? Why?
-
For each of the following circuits, find the output and design a simpler circuit that has the same output. (Hint: Find the circuit output by first finding the output of each gate, going from left to...
-
Explain the regulation of the secretions of the small intestine.
-
In 2012, Gale and Cathy Alexander hosted an exchange student, Axel Muller, for 9 months. Axel was part of International Student Exchange Programs (a qualified organization). Axel attended tenth grade...
-
Fisafolia Corporation has gross income from operations of $220,000 and operating expenses of $160,000 for 2012. The corporation also has $20,000 in dividends from publicly traded domestic...
-
Charlie's Green Lawn Care is a cash basis taxpayer. Charlie Adame, the sole proprietor, is considering delaying some of his December 2012 customer billings for lawn care into the next year. In...
-
This exercise considers the data described in the Section 13.2.2 ratemaking classification example using data in Table 13.3 Table 13.3 . a. Fit a gamma regression model using a log-link function with...
-
This exercise considers data from the Medical Expenditure Panel Survey (MEPS) described in Exercise 1.1 and Section 11.4. Our dependent variable consists of the number of outpatient (COUNTOP) visits....
-
Verify that the Tweedie distribution is a member of the linear exponential family of distributions by checking equation (13.9). In particular, provide an expression for \(S(y, \phi)\) (note that...
Study smarter with the SolutionInn App