Assignemnt #76 and Coolatz Sequence
Code
/// Name: Brian Phillips
/// Period: 5
/// Program name: Coolatz.java
/// File Name: Coolatz Sequence
/// Date Finished: 2/22/2016
import java.util.Scanner;
public class Coolatz
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int n;
int s=0;
System.out.print("Starting number: ");
n = keyboard.nextInt();
while (n!=1)
{
if (n%2==0)
{
n=n/2;
s++;
System.out.print(n+"\t");
}
else if (n%2!=0)
{
n=3*n+1;
s++;
System.out.print(n+"\t");
}
}
System.out.println("");
System.out.println("Terminated after "+s+" steps.");
}
}
Picture of the output