Collatz

Code

import java.util.Scanner;

public class Collatz
{
	public static void main( String[] args )
	{
		Scanner keyboard = new Scanner(System.in);
        
        int num, num1;
        
        num1 = 1;
        
        System.out.println(" please choose a number ");
        num = keyboard.nextInt();
        
        while ( num != 1 )
        {
            if ( num % 2 == 0 )
                num = ( num/2 );
            else
                num = ((num*3)+1);
            System.out.println(num);
            num1++;
        }
        
        System.out.println( " It took " + num1 + " steps to get it to 1 " );
    }
}

Collatz

Assignment 76