/* * Name(s): * ID(s): * Sections(s): * * CS100: Program 1 * Fall 1999 * * Input any integer and repeatedly divide it by 2 if even * and multiply it by 3 and 1 if odd. Stop on reaching 1 or less. * */ import java.io.*; public class CUCSApplication { public static void main(String args[]) { int k; // initialize Text object in to read from standard input. TokenReader in = new TokenReader(System.in); // Read and write some numbers and strings System.out.println("Please enter an integer: "); // Read integer k = in.readInt(); // Perform algorithm while ( k > 1 ) if ( (k % 2 ) == 0) { // test if k is even k = k / 2; System.out.println(k + " after dividing by 2"); } else k = 3 * k + 1; System.out.println("Done!"); // need to add this line to prevent window // from vanishing in.waitUntilEnter(); } }