Thursday, July 27, 2017

Hailstone Sequence

/* * This program generates hailstone sequence 
 * Use internet to find out how hailstone sequence works.

public class HailstoneSequence {

    public static void sequenceCalculation(int num) {

        if(num == 0) {
            System.out.println("Please enter a natural number > 0:");
        while(num!=1) {
            if(num % 2 == 0) {
                num = num/2;
            } else {
                num = 3*num + 1;
            System.out.printf(", %d ", num);

    //main method    
public static void main(String [] args) {


   /*This program is not complete. It doesn't interact with the users.
  Use Scanner class to take user input and display the hailstone sequence.
 After doing some research you knew that the Hailstone sequence is a 
 sequence of numbers where the the nextnumber is division of 2 if the
 preceding num is even or if its odd then the following number will
 be 3 times the preceeding number plus 1.Mathematically:                 
                N(t+1) = N(t)/2 or 3N(t)+1; 
                       Where t = 1,2,3,4,...... ;             N = number;              

1 comment:

Werner Ebner said...

You really make it appear really easy along with your presentation but I in finding this topic to be really something that I feel I might never understand. It kind of feels too complicated and very wide for me. I am having a look forward to your subsequent submit, I will attempt to get the dangle of it! all of craigslist