1) 3 int 3.0 double 12 String 0 int 0 double 2) for (int i = 102; i >= 0; i = i - 3) { System.out.println(i); } for (int i = 0; i < 100000; i++) { if (isPrime(i)) { System.out.println(i); } } for (int i = 0; i < 5; i++) { for (int j = i; j < 5; j++) { System.out.print("*"); } System.out.println(); } 3) -No because foo requires as input an int but b is a double -Yes double -1 -Yes double 1 -No because wrong input to method chocolate -Yes int 1 4) 5 4 -Note that in the method printVariables(), a gets assigned the value of the first expression passed as input (which is the expression "b" which has value of 5). In the method printVariables() b gets assigned the value of the second expression passed as input (a) which has the value of 4. So it prints 5 4 4 5 - Here too, follow the rules of method calls. In swapVariables(), a is assigned the value of the first expression (4) and b is assigned the value of the 2nd expression (5). Remember that these are new variables since any variable in one method shares no relationship to a variable in another method other than perhaps having the same value. 01234024 100, 200, 5000 (trick is that x and y both store the same address after int[] y = x; So changing y[2] also changes x[2]. However, once y = new int[10]; is executed, y[0] no longer changes x[0]) 5) public class WebpageLog { private String url; private int visitors; public WebpageLog(String page) { this.url = page; this.visitors = 0; //not required since 0 is initialized for int anyway } public String getUrl() { return this.url; } public int getVisitorCount() { return this.visitors; } public void increaseVisitorCount() { this.visitors++; } } 6) public static compareCounts(WebpageLog log1, WebpageLog log2) { int count1 = log1.getVisitorCount(); int count2 = log2.getVisitorCount(); if (count1 < count2) { return -1; } else if (count1 > count2) { return 1; } else { return 0; } } 7) public static int maxValue(int[] array) { int max = array[0]; for (int i = 1; i < array.length; i++) { if (array[i] > max) { max = array[i]; } } return max; } 8) public static int[] countValues(int[] values, int maximum) { int[] counts = new int[maximum]; for (int i = 0; i < values.length; i++) { counts[values[i]]++; } return counts; } 9) import java.util.Scanner; public class ModeProgram { public static void main(String[] args) { Scanner reader = new Scanner(System.in); System.out.println("How many integer values would you like to enter?"); int size = reader.nextInt(); int[] values = new int[size]; int entered = 0; while (entered < size) { System.out.println("Please enter a number >= 0"); int next = reader.nextInt(); if (next > 0) { values[entered] = next; entered++; } else { System.out.println("Try again to enter a positive number"); } } int theMaximum = ArrayUtilities.maxValue(values); int[] counts = ArrayUtilities.countValues(values, theMaximum + 1); int timesMaxOccurred = ArrayUtilities.maxValue(counts); //now check for what index the element occurred timesMaxOccurred for (int i = 0; i < counts.length; i++) { if (counts[i] == timesMaxOccured) { System.out.println("The number " + i + " occurred the most."); } } } }