Statistics:
mean 21.688 (347.000/16) stddev 4.984 median 22.000 midrange 20.000-25.000 # avg 1 6.94 / 10 2 8.44 / 10 3 6.31 / 10
Suppose a user executes the following run() method and types the numbers 3.
public static void run() { int n = IO.readInt(); int i = 0; while(n != 1) { 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 Q1A { public static void run() { DrawableFrame w; w = new DrawableFrame(); w.show(); Graphics g = w.getGraphics(); g.fillRect(50, 50, 100, 100); g.setColor(Color.white); g.fillRect(75, 0, 50, 200); g.fillRect(0, 75, 200, 50); } }
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() { } }
n 3 10 5 16 8 4 2 1 i 0 1 2 3 4 5It prints ``5.''
import csbsju.cs160.*; public class CountPositives { public static void run() { int count = 0; while(true) { int n = IO.readInt(); if(n == 0) break; if(n > 0) ++count; } IO.println(count); } }