Assignemnt #76

Code

          /// Name: Holden Ganch
          /// Period: 7
          /// Program Name:  seventy sixth Program
          /// File Name: Baby.java
          /// Date Finished: 2/8/2016


    
        
           import java.util.Random;
           import java.util.Scanner;
            
            public class Collatz
            {
            	public static void main( String[] args )
            	{
            		Scanner keyboard = new Scanner(System.in);
                    Random r = new Random();
                    
                    int x, z;
                    z = 0;
                    System.out.print("Starting number: ");
                   x = keyboard.nextInt();
                   
                   while (x != 1)
                   {
                   if ( x % 2 == 0)
                   {
                   x = x / 2;
                   System.out.print( x + "    ");
                   }
                   else if (x % 2 == 1)
                   {
                   x = 3*x+1;
                   System.out.print(x+ "    ");
                   }
                   z++;
                    }
                    System.out.println("");
                    System.out.println("Finished after " + z + " steps");
                    }
                    }

    
   




    

Picture of the output

Assignment 76