Section 6.5 Check Point Questions4 questions 

6.5.1
How is an argument passed to a method? Can the argument have the same name as its parameter?
6.5.2
Identify and correct the errors in the following program:
 1   public class Test {
 2     public static void main(String[] args) {
 3       nPrintln(5, "Welcome to Java!");
 4     }
 5
 6     public static void nPrintln(String message, int n) {
 7       int n = 1;
 8       for (int i = 0; i < n; i++)
 9         System.out.println(message);
10     }
11  }
6.5.3
What is pass-by-value? Show the result of the following programs.
(a)
public class Test {
  public static void main(String[] args) {
    int max = 0;
    max(1, 2, max);
    System.out.println(max);
  }

  public static void max(
      int value1, int value2, int max) {
    if (value1 > value2)
      max = value1;
    else
      max = value2;
  }
}

(b)
public class Test {
  public static void main(String[] args) {
    int i = 1;
    while (i <= 6) {
      method1(i, 2);
      i++;
    }
  }

  public static void method1(
      int i, int num) {   
    for (int j = 1; j <= i; j++) {
      System.out.print(num + " ");
      num *= 2;
    }
      
    System.out.println();
  }
}

(c)
public class Test {
  public static void main(String[] args) {
    // Initialize times
    int times = 3;
    System.out.println("Before the call,"
      + " variable times is " + times);
  
    // Invoke nPrintln and display times 
    nPrintln("Welcome to Java!", times);
    System.out.println("After the call," 
      + " variable times is " + times);
  }

  // Print the message n times
  public static void nPrintln(
      String message, int n) {
    while (n > 0) {
      System.out.println("n = " + n);
      System.out.println(message);
      n--;
    }
  }
}

(d)
public class Test {
  public static void main(String[] args) {
    int i = 0;
    while (i <= 4) {
      method1(i);
      i++;
    }

    System.out.println("i is " + i);
  }

  public static void method1(int i) {
    do {
      if (i % 3 != 0)
        System.out.print(i + " ");
      i--;
    }
    while (i >= 1);

    System.out.println();
  }
}
6.5.4
For (a) in the preceding question, show the contents of the activation records in the call stack just before the method max is invoked, just as max is entered, just before max is returned, and right after max is returned.