Assignment = Collataz Sequence
Code
/// Name: Sam Wilson
/// Period: 6
/// Program Name: Collatz
/// File Name: Collatz Sequence.java
/// Date Finished: 2/15/16
import java.util.Scanner;
public class seq
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int x, z;
System.out.print("Starting Number: ");
x = keyboard.nextInt();
z = 0;
while ( x != 1)
{
System.out.print( x+" ");
z++;
if ( (x%2) == 0 )
{
x = x/2;
}
else
{
x = (3*x) + 1;
}
}
System.out.print("1");
System.out.println();
System.out.println(" Terminated after "+z+" steps.");
System.out.println();
}
}
Picture of the output