One-page version suitable for printing.
Statistics:
(All numbers are out of the possible 80 points.)mean 55.674 (2561.000/46) stddev 10.966 median 55.000 midrange 48.000-65.000 # avg 1 8.67 / 10 2 5.48 / 10 3 12.06 / 15 4 12.50 / 20 5 16.96 / 25
Suppose a user executes the below run() method.
public static void run() { int n = 26; int k = 0; for(; n != 0; n /= 2) { if(n % 2 == 1) { k++; } } IO.println(k); }
n k
What distinguishes the purpose of a class variable from an instance variable? I am not asking how they are syntactically distinguished in Java. (In Java, an instance variable is declared directly inside the class. A class variable is also, but it additionally includes the static keyword.)
Fill in the below method so that, when executed, it reads an integer n from the user and displays the positive even integers that are less than or equal to n, in ascending order. Following is a sample transcript illustrating how an execution of the method should appear.
Number? 8 2 4 6 8
public static void run() { }
Complete the below class method so that it reads two strings from the user and displays ``yes'' if the second string includes only characters from the first, and ``no'' if it contains any characters that the first does not include.
For example, I should be able to execute your method and see the following. (Boldface indicates what the user types.)
Or I might see the following. In this example, it prints ``no'' because broil includes the letter o, which does not occur in brillig.brillig glib yes
brillig broil no
public static void run() { }
To accomplish this, you may find the following String instance methods useful. We discussed these in class.
At right, write a definition of a new type, called IntRange, representing a range of integers. This class should support the following instance methods.
public static void run() { IntRange range = new IntRange(2, 4); IO.println(range.getSize()); // this prints ``3'' IO.println(range.contains(1)); // this prints ``false'' IO.println(range.contains(3)); // this prints ``true'' IO.println(range.contains(4)); // this prints ``true'' IO.println(range.contains(5)); // this prints ``false'' }
public class IntRange { }