1. Consider the following program fragment.
public class One {
  public static void main(String[] args) {
    int size = 10, nuf, fun;
    for (nuf = 0; nuf < size; nuf++) { 
      for (fun = 0; fun < size; fun++) 
        if ( fun == 0 || 
             fun == size - 1 || 
             __________________ )
          System.out.print(" *"); 
        else 
          System.out.print("  "); 
      System.out.println(); 
    }
  } 
}
What's need for the output to resemble an H? Explain.

2. You compile and run the following program. What does it print?

class One {
  public static void main(String[] args) {
    boolean p = false, 
            q = true, 
            r = true;
    System.out.println(! (p && (q || !r))); 
  }
} 
Please explain your answer.

3. Consider the following program fragment.

int x = 8, y = 0; if (x < 10) { if (x > 5) y = 1; else y = 2; }
What value does y have at the end? Please explain your answer.

4. Consider the following program fragment.

int x = 8, y = 0; { if (x < 10) if (x > 5) y = 1; } else y = 2; 
What value does y have at the end? Please explain your answer.

5. How many question marks will be printed by the following code fragment?

for (int i = -10; i <= 10; i = i + 3)
  System.out.print("?"); 
Please explain your answer.

6. Consider the following fragment. What does it print?

int x = 3, y = 11; 
x = x + y;
y = x - y; 
x = x - y; 
System.out.println("(" + x + ", " + y + ")"); 
Please explain your answer.

7. What gets printed when you compile and run the following program?

class One {
  public static void main(String[] args) {
    System.out.println(kanga(kanga(kanga(kanga(ru(1, 2), 
                                               1), 
                                         2), 
                                   ru(1, 2)),
                             1)); 
  } 
  public static int kanga(int a, int b) {
    return a + b;
  } 
  public static int ru(int a, int b) {
    return a - b; 
  }
} 
Please explain your answer.

8. Consider the following code fragment, what does it print?

String plum = "nectarine";  
System.out.println((char)('Q' - plum.length())); 
Please explain your answer.

9. You compile and run this program. What's the output?

public class Nine {
    public static void main(String[] args) {
	Nine a = new Nine(); 
	Nine b = new Nine(); 
	a.nuf(1); 
	a.fun(); 
	b.nuf(3); 
	b.fun(); 
	a.nuf(5); 
	System.out.println(Nine.m + a.n); 
    } 
    void nuf(int p) {
	this.n = this.n + p; 
	Nine.m = Nine.m - p; 
    } 
    void fun() {
	int temp = this.n; 
	this.n = Nine.m; 
	Nine.m = temp; 
    } 
    int n; 
    static int m; 
} 
Please explain your answer.

10. Explain what each of the following two program segments compute:
x = 2;
y = x + x;
s = "2"; 
t = s + s;

11. How do you get the first character of a string? The last character? How do you remove the first character? The last character?