Java program to generate the Hailstone sequence (Collatz conjecture).

This program generates the Hailstone sequence (Collatz conjecture) of a number entered by the user.
Collatz conjecture at WikiPedia: Link.
In the Collatz conjecture, to find the next number in the sequence, we divide the current number by 2 if it is even or multiply it by 3 and add by 1 if it is odd.

So the sequence for number 6 would be: 6, 3, 10, 5, 16, 8, 4, 2, 1.

Program:

Tested in Eclipse.

The following two tabs change content below.

One thought on “Java program to generate the Hailstone sequence (Collatz conjecture).

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">