Assignment #76 Collatz Sequence
Code
///Name: Morgan Kaplan
///Period: 5
///Project Name: Collatz Sequence
///File Name: CC.java
import java.util.Scanner;
public class CS
{
public static void main( String[] args)
{
Scanner momo= new Scanner(System.in);
int n,a,b,times=0;
System.out.println(" Enter a number: ");
n=momo.nextInt();
int c=n;
do
{
if (c% 2 == 0)
{
c=(c/2);
System.out.println( " "+times+". " + c + " ");
}
else
{
c=((c*3)+1);
System.out.println( " "+times+". " + c + " ");
}
times++;
}
while (c!=1);
}
}
Picture of Output