Assignemnt # and
Code
///Name: Dakota Donahue
///Period: 5
///Project Name:
///File Name:
///Date: 3/10/2016
import java.util.Scanner;
public class CollatzSequence
{
public static void main( String [] args )
{
Scanner keyboard = new Scanner(System.in);
System.out.print( "Starting number: " );
int n = keyboard.nextInt();
int steps = 0;
int counter = 0;
int answer = 0;
while ( n != 1 )
{
if ( counter == 0 )
System.out.println( n );
if ( n % 2 == 0 )
{
n = n / 2;
steps++;
counter++;
}
else
{
n = n * 3 + 1;
steps++;
counter++;
}
if ( n % 10 != 0 )
{
System.out.println(n);
}
else
{
System.out.println(n);
}
}
System.out.println(" Terminated after " +steps+ " steps. ");
}
}