York University


Solutions of EECS1021 Quiz 1

The correct answer is in bold red.

  1. [1 mark] What is the console output of the following lines of Java code?

    boolean b1 = false;
    boolean b2 = false;
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    b2 = true;
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    b1 = true;
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    b2 = false;				
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    
    1. ===
      false false
      ===
      false true
      ===
      true true
      ===
      false true
      
    2. ===
      false false
      ===
      true false
      ===
      true true
      ===
      false true
      
    3. ===
      false false
      ===
      false true
      ===
      true true
      ===
      true false
      
    4. ===
      false false
      ===
      true false
      ===
      true true
      ===
      true false
      

  2. [1 mark] What is the console output of the following lines of Java code?

    boolean b1 = false;
    boolean b2 = true;
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    b2 = false;
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    b1 = true;
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    b2 = true;				
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    
    1. ===
      false true
      ===
      false false
      ===
      false true
      ===
      true true
      
    2. ===
      false true
      ===
      false false
      ===
      true false
      ===
      true true
      
    3. ===
      true false
      ===
      false false
      ===
      false true
      ===
      true true
      
    4. ===
      true false
      ===
      false false
      ===
      true false
      ===
      true true
      

  3. [1 mark] What is the console output of the following lines of Java code?

    boolean b1 = true;
    boolean b2 = false;
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    b2 = true;
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    b1 = false;
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    b2 = false;				
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    
    1. ===
      false true
      ===
      true true
      ===
      false true
      ===
      false false
      
    2. ===
      false true
      ===
      true true
      ===
      true false
      ===
      false false
      
    3. ===
      true false
      ===
      true true
      ===
      false true
      ===
      false false
      
    4. ===
      true false
      ===
      true true
      ===
      true false
      ===
      false false
      

  4. [1 mark] What is the console output of the following lines of Java code?

    boolean b1 = true;
    boolean b2 = true;
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    b2 = false;
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    b1 = false;
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    b2 = true;				
    System.out.println("===");  
    System.out.println((b1 && b2) + " " + (b1 || b2));
    
    1. ===
      true true
      ===
      false true
      ===
      false false
      ===
      false true
      
    2. ===
      true true
      ===
      false true
      ===
      false false
      ===
      true false
      
    3. ===
      true true
      ===
      true false
      ===
      false false
      ===
      false true
      
    4. ===
      true true
      ===
      true false
      ===
      false false
      ===
      true false
      

  5. [1 mark] What is the console output of the following lines of Java code?

    boolean p = false;
    boolean q = false;
    boolean conjunction = p && q;
    boolean disjunction = p || q;
    System.out.println("===");
    System.out.println(!conjunction);
    System.out.println(!disjunction);
    p = true;
    System.out.println("===");
    System.out.println(!conjunction);
    System.out.println(!disjunction);
    
    1. ===
      true
      true
      ===
      true
      true
      
    2. ===
      true
      true
      ===
      true
      false
      
    3. ===
      false
      false
      ===
      false
      false
      
    4. ===
      false
      false
      ===
      false
      true
      

  6. [1 mark] What is the console output of the following lines of Java code?

    boolean p = false;
    boolean q = true;
    boolean conjunction = p && q;
    boolean disjunction = p || q;
    System.out.println("===");
    System.out.println(!conjunction);
    System.out.println(!disjunction);
    p = true;
    System.out.println("===");
    System.out.println(!conjunction);
    System.out.println(!disjunction);
    
    1. ===
      true
      false
      ===
      true
      false
      
    2. ===
      true
      false
      ===
      false
      false
      
    3. ===
      false
      true
      ===
      false
      true
      
    4. ===
      false
      true
      ===
      true
      true
      

  7. [1 mark] What is the console output of the following lines of Java code?

    boolean p = true;
    boolean q = false;
    boolean conjunction = p && q;
    boolean disjunction = p || q;
    System.out.println("===");
    System.out.println(!disjunction);
    System.out.println(!conjunction);
    q = true;
    System.out.println("===");
    System.out.println(!disjunction);
    System.out.println(!conjunction);
    
    1. ===
      false
      true
      ===
      false
      true
      
    2. ===
      false
      true
      ===
      false
      false
      
    3. ===
      true
      false
      ===
      true
      false
      
    4. ===
      true
      false
      ===
      true
      true
      

  8. [1 mark] What is the console output of the following lines of Java code?

    boolean p = true;
    boolean q = true;
    boolean conjunction = p && q;
    boolean disjunction = p || q;
    System.out.println("===");
    System.out.println(!conjunction);
    System.out.println(!disjunction);
    p = false;
    System.out.println("===");
    System.out.println(!conjunction);
    System.out.println(!disjunction);
    
    1. ===
      false
      false
      ===
      false
      false
      
    2. ===
      false
      false
      ===
      true
      false
      
    3. ===
      true
      true
      ===
      true
      true
      
    4. ===
      true
      true
      ===
      false
      true
      

  9. [1 mark] Assume that we already declare an int variable called i. Which of the following boolean expressions always evaluates to true (despite the value of i)?
    1. i >= 5 && 10 >= i
      
    2. i >= 5 || 10 >= i
      
    3. i < 5 && 10 < i
      
    4. i < 5 || 10 < i
      

  10. [1 mark] Assume that we already declare an int variable called i. Which of the following boolean expressions always evaluates to true (despite the value of i)?
    1. 17 >= i && i >= 4
      
    2. 17 >= i || i >= 4
      
    3. 17 < i && i < 4
      
    4. 17 < i || i < 4
      

  11. [1 mark] Assume that we already declare an int variable called i. Which of the following boolean expressions always evaluates to false (despite the value of i)?
    1. i >= 5 && 10 >= i
      
    2. i >= 5 || 10 >= i
      
    3. i < 5 && 10 < i
      
    4. i < 5 || 10 < i
      

  12. [1 mark] Assume that we already declare an int variable called i. Which of the following boolean expressions always evaluates to false (despite the value of i)?
    1. 17 >= i && i >= 4
      
    2. 17 >= i || i >= 4
      
    3. 17 < i && i < 4
      
    4. 17 < i || i < 4
      

  13. [1 mark] What is the console output of the following lines of Java code?

    int i = 5;
    int j = 7;
    int k = 9;
    String s = "Hello ";
    System.out.println(s + i + j + k);
    System.out.println((s + i) + j + k);
    System.out.println(s + (i + j) + k);
    
    1. Hello 579
      Hello 579
      Hello 129
      
    2. Hello 579
      Hello 516
      Hello 129
      
    3. Hello 21
      Hello 516
      Hello 129
      
    4. Hello 579
      Hello 579
      Hello 579
      
    5. There is a compile-time error in the above code, so it simply cannot be run to produce console output.

  14. [1 mark] What is the console output of the following lines of Java code?

    int i = 11;
    int j = 12;
    int k = 13;
    String s = "Hello ";
    System.out.println(s + i + j + k);
    System.out.println((s + i) + j + k);
    System.out.println(s + (i + j) + k);
    
    1. Hello 111213
      Hello 111213
      Hello 2313
      
    2. Hello 111213
      Hello 1125
      Hello 2313
      
    3. Hello 36
      Hello 1125
      Hello 2313
      
    4. Hello 111213
      Hello 111213
      Hello 111213
      
    5. There is a compile-time error in the above code, so it simply cannot be run to produce console output.

  15. [1 mark] What is the console output of the following lines of Java code?

    int i = 25;
    int j = 11;
    int k = 3;
    System.out.println(((i % j) * (j / k)) % 4);
    
    1. 0
      
    2. 1
      
    3. 2
      
    4. 3
      
    5. 4
      
    6. There is a compile-time error in the above code, so it simply cannot be run to produce console output.

  16. [1 mark] What is the console output of the following lines of Java code?

    int i = 37;
    int j = 11;
    int k = 3;
    System.out.println(((i % j) * (j / k)) % 4);
    
    1. 0
      
    2. 1
      
    3. 2
      
    4. 3
      
    5. 4
      
    6. There is a compile-time error in the above code, so it simply cannot be run to produce console output.

  17. [1 mark] What is the console output of the following lines of Java code?

    int i = 13;
    int j = 2;
    System.out.println(i / j);
    System.out.println( (double) (i  / j));
    System.out.println(((double)  i) / j );
    System.out.println( (double)  i  / j );
    
    1. 6
      6.0
      6.5
      6.5
      
    2. 6.5
      6.5
      6.5
      6.5
      
    3. 6
      6.0
      6.0
      6.0
      
    4. 6
      6.0
      6.5
      6.0
      
    5. There is a compile-time error in the above code, so it simply cannot be run to produce console output.

  18. [1 mark] What is the console output of the following lines of Java code?

    int i = 14;
    int j = 4;
    System.out.println(i / j);
    System.out.println( (double) (i  / j));
    System.out.println(((double)  i) / j );
    System.out.println( (double)  i  / j );
    
    1. 3
      3.0
      3.5
      3.5
      
    2. 3.5
      3.5
      3.5
      3.5
      
    3. 3
      3.0
      3.0
      3.0
      
    4. 3
      3.0
      3.5
      3.0
      
    5. There is a compile-time error in the above code, so it simply cannot be run to produce console output.

  19. [1 mark] What is the console output of the following lines of Java code?

    double a = 3.1415926;  
    double b = (int) a; 
    System.out.println(b);
    
    int c = (int) a; 
    System.out.println(c);
    
    double d = (c * 5) / 2; 
    System.out.println(d);
    
    d = (b * 5) / 2;
    System.out.println(d);
    
    1. 3.0
      3
      7.0
      7.5
      
    2. 3.0
      3.0
      7.0
      7.5
      
    3. 3.0
      3.0
      7.5
      7.5
      
    4. 3
      3
      7.0
      7.0
      

  20. [1 mark] What is the console output of the following lines of Java code?

    double a = 3.1415926;  
    double b = (int) a; 
    System.out.println(b);
    
    int c = (int) a; 
    System.out.println(c);
    
    double d = (c * 9) / 2; 
    System.out.println(d);
    
    d = (b * 9) / 2;
    System.out.println(d);
    
    1. 3.0
      3
      13.0
      13.5
      
    2. 3.0
      3.0
      13.0
      13.5
      
    3. 3.0
      3.0
      13.5
      13.5
      
    4. 3
      3
      13.0
      13.0
      

  21. [1 mark] What is the console output of the following lines of Java code?

    double a = 3.4;
    double b = ((int) a) * 3; 
    System.out.println(b);
    
    double c = ((int) a) + 2.7; 
    System.out.println(c);
    
    double d = (( (int) c ) * 3) / 2; 
    System.out.println(d);
    
    d = (b * 3) / 2;
    System.out.println(d);
    
    1. 9.0
      5.7
      7.0
      13.5
      
    2. 10.0
      6.0
      9.0
      15.0
      
    3. 10.2
      6.1
      9.15
      15.3
      
    4. 9
      5
      7
      13
      

  22. [1 mark] What does the equal sign (=) mean in Java?
    1. The assignment operator.
    2. The relational comparison operator.
    3. The arithmetic quotient operator.
    4. The arithmetic remainder operator.

  23. [1 mark] What does the equal-equal sign (==) mean in Java?
    1. The assignment operator.
    2. The relational comparison operator.
    3. The arithmetic quotient operator.
    4. The arithmetic remainder operator.

  24. [1 mark] What does the percentage sign (%) mean in Java?
    1. The assignment operator.
    2. The relational comparison operator.
    3. The arithmetic quotient operator.
    4. The arithmetic remainder operator.

  25. [1 mark] What does the operator && mean in Java?
    1. The logical conjunction operator.
    2. The logical disjunction operator.
    3. The logical negation operator.
    4. The concatenation operator.

  26. [1 mark] What does the operator || mean in Java?
    1. The logical conjunction operator.
    2. The logical disjunction operator.
    3. The logical negation operator.
    4. The concatenation operator.

  27. [1 mark] What does the operator || mean in Java?
    1. The logical conjunction operator.
    2. The logical disjunction operator.
    3. The logical negation operator.
    4. The concatenation operator.

  28. [1 mark] Which one of the following expressions contains type error(s) so that it does not compile?
    1. "I " + "Love " + 1021
      
    2. ((double) 11 / 3) + " is what?"
      
    3. ((13 % 3) + "234") + 56 + ("(13 % 3) * 234")
      
    4. ((13 % 3) + "234") / 56 + ((13 % 3) * 234)
      
    5. All of the above expressions contain some type error(s).
    6. None of the above expressions contain some type error(s).