CS 1073 Introductory Programming
|
15: 15, 23, 35, 53, 80, 40, 20, 10, 5, 8, 4, 2, 1
27: 27, 41, 62, 31, 47, 71, 107, 161, 242, 121,
182, 91, 137, 206, 103, 155, 233, 350, 175, 263,
395, 593, 890, 445, 668, 334, 167, 251, 377, 566,
283, 425, 638, 319, 479, 719, 1079, 1619, 2429, 3644,
1822, 911, 1367, 2051, 3077, 4616, 2308, 1154, 577, 866,
433, 650, 325, 488, 244, 122, 61, 92, 46, 23,
35, 53, 80, 40, 20, 10, 5, 8, 4, 2, 1
| Three-halves Calculation |
|---|
// ThreeHalves.java: carry out the 3/2 calculation on a positive int.
public class ThreeHalves {
public static void main (String[] args) {
// n: initial value for three-halves sequence
int n = 15;
System.out.println(n);
//==============================================================
// Carry out the ThreeHalves calculation
// ... fill in code here to repeatedly replacing n
// by either (3n+1)/2, if n is odd, or by
// n/2, if n is even.
// (n is even in case n%2 == 0.)
// (n is odd in case n%2 == 1.)
// Continue until n gets to 1, if it does.
} // end of main
}
|