Preview

Hello

Good Essays
Open Document
Open Document
888 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Hello
—Hailstone Sequences [12 marks] A hailstone sequence is a sequence of integers found by applying the following rule: Hailstone Iteration: For an integer n in a hailstone sequence, the next item in the sequence is • 3n + 1 if n is odd, or • n / 2 if n is even. For example, the hailstone sequence starting at 6 is 6 ⇒ 3 ⇒ 10 ⇒ 5 ⇒ 16 ⇒ 8 ⇒ 4 ⇒ 2 ⇒ 1. The sequence ends when 1 is reached. The name "hailstone sequence" stems from the way the values in the sequence go up and down, as a hailstone does in the clouds before it falls to earth. Collatz (1937) conjectured that for any starting integer, 1 would eventually be reached. So far there is no proof, making the Collatz conjecture a famous unresolved problem in mathematics. Write a complete Java program that will: 1) prompt the user to enter an integer N (in this document we call the input number N, but of course in your program it must have a proper identifier); 2) scan the integers from 1 to N, where N is the user’s input, and find the hailstone sequence starting at each integer and ending at 1 (see the example below); 3) determine the largest hailstone number in each sequence, and the hailstone sequence containing the largest number overall; 4) print out the hailstone sequence with the largest number. For example, if N = 5, the following hailstone sequences will be produced: 1: 1 [highest number: 1] 2: 2 ⇒ 1 [highest number: 2] 3: 3 ⇒ 10 ⇒ 5 ⇒ 16 ⇒ 8 ⇒ 4 ⇒ 2 ⇒ 1 [highest number: 16] 4: 4 ⇒ 2 ⇒ 1 [highest number: 4] 5: 5 ⇒ 16 ⇒ 8 ⇒ 4 ⇒ 2 ⇒ 1 [highest number: 16] The highest number reached is 16. It appears in sequences for starting numbers 3 and 5. Where two sequences have the same largest hailstone number, choose the one with the smaller starting number. In this case the starting number 3 gives the largest hailstone number. The structure of your program should look like this: That is, main calls getPositiveInt to input from the user the maximum starting number of

You May Also Find These Documents Helpful

  • Satisfactory Essays

    M1 Week 3

    • 1315 Words
    • 6 Pages

    In order to find the makespan for the sequence we need to draw a GANTT chart:…

    • 1315 Words
    • 6 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Hrm 531 Week 3 Quiz

    • 3024 Words
    • 13 Pages

    | Fill in the missing word.In anatomical terms, the brain lies ……. to the eyes.Answer…

    • 3024 Words
    • 13 Pages
    Satisfactory Essays
  • Good Essays

    Psy/315 Week 4

    • 631 Words
    • 3 Pages

    0, 1, 1, 3, 0, 0, 2, 5, 0, 1, 1, 2, 0, 1, 1…

    • 631 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Pow 1 Spiralateral

    • 543 Words
    • 3 Pages

    I also discovered that if they had an even number of numerals in the sequence, but they repeated a number then it would end. All spiralaterals with an odd number of numerals will end where the started and continue to cycle around. If a spiralateral repeats a number then it must end; this applies to all sequences whether they be odd or even. This must be true because the repeated number turn the spiralateral back towards the pattern. In the spiralaterals that never end the repeated number changes the way the group of segments are going and causes the spiralateral to complete…

    • 543 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    MAT 126 Week 1 Quiz

    • 767 Words
    • 4 Pages

    8. Use inductive reasoning to find a pattern, and then make a reasonable conjecture for the next number in the sequence. 7 8 10 13 17 22 28 ____…

    • 767 Words
    • 4 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Pt1420 Unit 7 Study Guide

    • 582 Words
    • 3 Pages

    2.Write a program to (a) display a “?” (b) read two decimal digits whose sum less than 10 (c) display them and their sum on the next line. Page: 80…

    • 582 Words
    • 3 Pages
    Satisfactory Essays
  • Better Essays

    45, 63, 78, 89, 95, 99, 105, 141, 148, 156, 160, 161, 164, 212, 217…

    • 2271 Words
    • 10 Pages
    Better Essays
  • Good Essays

    Imp 2 Pow: Kick It

    • 591 Words
    • 3 Pages

    This pattern is a little bit more tricky, but i noticed that its just like the threes it goes up three every number but instead of zero being the starting number it is five.…

    • 591 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    24, 46, 23, 31, 32, 45, 34, 37, 28, 40, 34, 38, 40, 52, 31, 33, 15, 27, 36, 40…

    • 1224 Words
    • 5 Pages
    Powerful Essays
  • Powerful Essays

    sequence of the 26 steps, starting with “1” for the first step and ending with “26” for…

    • 7169 Words
    • 46 Pages
    Powerful Essays
  • Good Essays

    algebra final

    • 555 Words
    • 6 Pages

    In , is a right angle. Find the remaining sides and angles. Round your answers to the nearest tenth.…

    • 555 Words
    • 6 Pages
    Good Essays
  • Powerful Essays

    Psychology Timeline

    • 2125 Words
    • 9 Pages

    10, 13, 10, 12, 11, 7, 12, 11, 6, 11, 12, 11, 8, 10, 9…

    • 2125 Words
    • 9 Pages
    Powerful Essays
  • Good Essays

    Programming Homework

    • 366 Words
    • 2 Pages

    Provide your analysis for the following problem statement: You need to write a program that would calculate the results for the multiplication table up from 1 to 100. (For example, 1X1, 1X2, 1X3 … 1X10, 2X1, 2X2 …. 10X2 … 10x10). Your program should print the output for each step and output a new line after 10 items.…

    • 366 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    health and social care

    • 4421 Words
    • 18 Pages

    10 Progression…

    • 4421 Words
    • 18 Pages
    Satisfactory Essays
  • Powerful Essays

    Colored Girls

    • 19130 Words
    • 77 Pages

    for colored girls who have considered suicide/when the rainbow is enuf Study Guide consists of approx. 53 pages of summaries and analysis on for colored girls who have considered suicide/when the rainbow is enuf by Ntozake Shange. Browse the literature study guide below:…

    • 19130 Words
    • 77 Pages
    Powerful Essays

Related Topics