Write a program that reads in a number from the user

Assignment Help Programming Languages
Reference no: EM131251209

Douglas Hofstadter's Pulitzer-prize-winning book Gödel, Escher, Bach contains many interesting mathematical puzzles. In Chapter XII, Hofstadter mentions a wonderful problem that is well within the scope of the control statements in Java. The problem can be expressed as follows: Pick some positive integer and call it n. If n is even, divide it by two. If n is odd, multiply it by three and add one. Continue this process until n is equal to 1. Hofstadter illustrates this process with the following example, starting with the number n = 15:

15 is odd, so I make 3n+1: 46
46 is even, so I take half: 23
23 is odd, so I make 3n+1: 70
70 is even, so I take half: 35
35 is odd, so I make 3n+1: 106
106 is even, so I take half: 53
53 is odd, so I make 3n+1: 160
160 is even, so I take half: 80
80 is even, so I take half: 40
40 is even, so I take half: 20
20 is even, so I take half: 10
10 is even, so I take half: 5
5 is odd, so I make 3n+1: 16
16 is even, so I take half: 8
8 is even, so I take half: 4
4 is even, so I take half: 2
2 is even, so I take half: 1

As you can see from this example, the numbers go up and down, but eventually-at least for all numbers that have ever been tried-come down to end in 1. In some respects, this process is reminiscent of the formation of hailstones, which get carried upward by the winds over and over again before they finally descend to the ground. Because of this analogy, this sequence of numbers is usually called the Hailstone sequence, although it goes by many other names as well.

Write a program that reads in a number from the user and then displays the Hailstone sequence for that number, followed by a line showing the number of steps taken to reach 1.

Reference no: EM131251209

Questions Cloud

New customers they sign up for new magazine subscriptions : Outbound sales representatives receive a $20 commission on all new customers they sign up for new magazine subscriptions. Each outbound sales representative works 40 hours. Because these employees are paid solely on commission, the employer must ensu..
Write a program to compute the total bonus amount earned : An employee has committed to save $2000 per month. Write a program to compute the total bonus amount earned by these two employees in the year.
Analyze the prioritizing process : Analyze the prioritizing process at D. D. Williamson. Suggest two (2) recommendations to improve the prioritizing process. Create a scenario where the implemented process at D. D. Williamson would not work.
Deliver package to customer before traveling home : Nadine is an administrative assistant for her employer. At the end of her shift one day, her employer requires her to deliver a package to a customer before traveling home. She spends two hours driving to the customer site, and then three hours drivi..
Write a program that reads in a number from the user : Write a program that reads in a number from the user and then displays the Hailstone sequence for that number, followed by a line showing the number of steps taken to reach 1.
Create the code for a login system : SGA1789 Build Dynamic Websites Workbook Assignment. Using PHP session management features create the code for a login system. This will be used for security and access control of the database component you developed in Assessment Task. Ensure there..
Analyze the prioritizing process : Analyze the prioritizing process at D. D. Williamson. Suggest two (2) recommendations to improve the prioritizing process. Create a scenario where the implemented process at D. D. Williamson would not work.
Sole proprietor who performs excavating services : In July of 2009, Mr. Mann, a sole proprietor who performs excavating services, purchased and put to use for business a piece of heavy equipment for $36,500. This piece of equipment was depreciated using the MACRS 150% DB method of depreciation over t..
Corporate social responsibility : 1. In terms of corporate social responsibility, discuss three ways that a company can focus on the needs of its stakeholders without neglecting its shareholder obligations.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd