One-page version suitable for printing.
Statistics:
mean 23.767 (713.000/30) stddev 3.303 median 24.000 midrange 22.000-26.000 # avg 1 6.9 / 10 2 9.3 / 10 3 7.57 / 10
Suppose a user executes the following run() method and types the numbers 13.
public static void run() { int n = IO.readInt(); int i = 0; while(n != 4) { if(n % 2 == 1) n = 3 * n + 1; if(n % 2 == 0) n /= 2; i++; } IO.println(i); }
n i
import csbsju.cs160.*; public class Q1B { public static void run() { DrawableFrame w; w = new DrawableFrame(); w.show(); Graphics g = w.getGraphics(); g.fillRect(80, 40, 40, 120); g.fillRect(40, 80, 120, 40); g.setColor(Color.white); g.fillRect(80, 80, 40, 40); } }
Fill in run() so that, when executed, the method will count the number of positive numbers the user types before the user types 0. A user executing the method should see the following, for example. (Boldface indicates what the user types.)
123 -2 8 123 0 3
import csbsju.cs160.*; public class CountPositives { public static void run() { } }