Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Review Questions

5.15Which of the following expressions evaluate to true?

Select the two correct answers.

  1. (false | true)

  2. (null != null)

  3. (4 <= 4)

  4. (!true)

  5. (true & false)

5.16Which statements are true?

Select the two correct answers.

  1. The remainder operator % can only be used with integral operands.

  2. Short-circuit evaluation occurs with boolean logical operators.

  3. The arithmetic operators *, /, and % have the same level of precedence.

  4. A short value ranges from -128 to +127, inclusive.

  5. (+15) is a legal expression.

5.17Which statements are true about the lines of output printed by the following program?
public class BoolOp {
  static void op(boolean a, boolean b) {
    boolean c = a != b;
    boolean d = a ^ b;
    boolean e = c == d;
    System.out.println(e);
  }

  public static void main(String[] args) {
    op(false, false);
    op(true, false);
    op(false, true);
    op(true, true);
  }
}

Select the three correct answers.

  1. All lines printed are the same.

  2. At least one line contains false.

  3. At least one line contains true.

  4. The first line contains false.

  5. The last line contains true.

5.18What is the result of running the following program?
public class OperandOrder {
  public static void main(String[] args) {
    int i = 0;
    int[] a = {3,6};
    a[i] = i = 9;
    System.out.println(i + " " + a[0] + " " + a[1]);
  }
}

Select the one correct answer.

  1. When run, the program throws an exception of type ArrayIndexOutOfBoundsException.

  2. When run, the program will print "9 9 6".

  3. When run, the program will print "9 0 6".

  4. When run, the program will print "9 3 6".

  5. When run, the program will print "9 3 9".

5.19Which statements are true about the output from the following program?
public class Logic {
  public static void main(String[] args) {
    int i = 0;
    int j = 0;

    boolean t = true;
    boolean r;

    r = (t & 0 < (i+=1));
    r = (t && 0 < (i+=2));
    r = (t | 0 < (j+=1));
    r = (t || 0 < (j+=2));
    System.out.println(i + " " + j);
  }
}

Select the two correct answers.

  1. The first digit printed is 1.

  2. The first digit printed is 2.

  3. The first digit printed is 3.

  4. The second digit printed is 1.

  5. The second digit printed is 2.

  6. The second digit printed is 3.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint