import java.util.Scanner; public class Collatz { public static void main( String[] args ) { Scanner keyboard = new Scanner(System.in); int loops = 0; System.out.print("Starting number: "); int value = keyboard.nextInt(); System.out.print(value+ "\t"); while (value > 1) { if (value%2 == 0) { value = value/2; } else { value = value*3+1; } loops ++; System.out.print(value+ "\t"); } System.out.println("\nSequence finished after " +loops+ " steps."); } }