Assignment 76, Collatz Sequence
Code
///Name: Stella Koliavas
///Period: 5
///File Name: ColSeq.java
///Date Finshed: 2/5/16
import java.util.Scanner;
public class ColSeq
{
public static void main(String[] args)
{
Scanner siri = new Scanner(System.in);
int num, x = 0;
System.out.println("Enter a number and I'll make it reach 1 by mathy stuff");
System.out.print("Number: ");
num = siri.nextInt();
while (num != 2)
{
if (num % 2 == 0)
{
num = num/2;
System.out.print(num/2 + "\t");
}
else
{
num = (3*num) + 1;
System.out.print((3*num) + 1 + "\t");
}
x++;
}
System.out.println(" ");
System.out.println("It took you "+ x +" steps to get to one!");
}}
Picture of the output