Code
/// Name: Afaf Nabeeha
/// Period: 7
/// Program Name: Collatz Sequence
/// File Name: Collatz.java
/// Date Finished: 1/29/2016 public class Collatz
import java.util.Scanner;
public class Collatz
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int input, counter;
input = 0;
counter = 0;
System.out.print( "Starting number: " );
input = keyboard.nextInt();
while ( input != 1 )
{
if (input % 2 == 0 )
{
input = input / 2;
}
else if ( input % 2 != 0 )
{
input = input*3 + 1;
}
System.out.print( input + "\t" );
counter++;
}
System.out.println( "Terminated after " + counter + " steps. " );
}
}
Picture of the output