Expressions and Output() - AP Computer Science A

  1. What is the result of 10 % 3 in Java?
    1. Modulus operator returns the remainder after division.
  2. Identify the error: System.out.println('Hello' - 'World');
    Operator '-' cannot be applied to Strings. Subtraction operator is not defined for String operands.
  3. What is the output of: System.out.println(4 + 2 * 3 - 1);?
    9. Order: 2×3=62 \times 3 = 6, then 4+6−1=94 + 6 - 1 = 9.
  4. How is a string concatenated with an integer in Java?
    Using the + operator. The ++ operator performs concatenation when one operand is a string.
  5. What is the output of: System.out.println(8 / 3.0);?
    2.6666666666666665. Double division produces precise floating-point result.
  6. What does the expression 2 * (3 + 4) evaluate to?
    14. Parentheses force addition first: (3+4)=7(3 + 4) = 7, then 2×7=142 \times 7 = 14.
  7. Identify the error: System.out.println('Sum: ' + 5 + 3);
    Output is 'Sum: 53', not 'Sum: 8'. String concatenation with ++ operator evaluates left-to-right without parentheses.
  8. How do you declare a constant in Java?
    Using the final keyword. Makes variables immutable after initialization.
  9. What is the result of: System.out.println(4 * 0.5);?
    2.0. Integer multiplied by double results in double type.
  10. What is the output of: System.out.println(9 / 2.0);?
    4.5. Double divisor produces floating-point division result.
  11. What is the operator used for modulus in Java?
    %. Returns the remainder of integer division.
  12. What is the result of: System.out.println(6.0 / 3);?
    2.0. Double dividend produces floating-point division.
  13. What is the result of: System.out.println('a' + 1);?
    98. Character 'a' has ASCII value 97, so 97+1=9897 + 1 = 98.
  14. What is the output of: System.out.println('A' + 'B');?
    131. ASCII values: A=65, B=66, so 65+66=13165 + 66 = 131.
  15. What is the result of: System.out.println(7 - 3 * 2);?
    1. Multiplication has higher precedence: 3×2=63 \times 2 = 6, then 7−6=17 - 6 = 1.
  16. What does System.out.print() do differently than println()?
    Output without a newline. Does not add a newline character after output.
  17. What is the output of: System.out.println(3.0 / 2);?
    1.5. Double division produces a floating-point result.
  18. What is the result of: System.out.println(12 / 5);?
    2. Integer division truncates the decimal portion.
  19. What will be printed: System.out.println('2' + 3 + 4);?
    234. Character '2' concatenates, then numeric addition occurs.
  20. What does the expression 2 + 3 * 4 evaluate to?
    14. Multiplication precedence: 3×4=123 \times 4 = 12, then 2+12=142 + 12 = 14.
  21. What is the output of: System.out.println('A' + 1);?
    66. Character 'A' has ASCII value 65, so 65+1=6665 + 1 = 66.
  22. What is the value of a boolean expression: 5 > 3 && 3 > 5?
    false. Second condition is false, making the entire AND expression false.
  23. What is the output of: System.out.println(5 + 2 * 3);?
    11. Multiplication precedence: 2×3=62 \times 3 = 6, then 5+6=115 + 6 = 11.
  24. What will be printed: System.out.println(true && false);?
    false. Logical AND requires both operands to be true.
  25. What is the output of: System.out.println(0.1 + 0.2 == 0.3);?
    false. Floating-point arithmetic precision issues cause inequality.
  26. What is the result of: System.out.println('Java' + 1 + 2);?
    Java12. String concatenation evaluates left-to-right without grouping.
  27. What is the result of: System.out.println(10 % 2);?
    0. 10 divided by 2 has no remainder.
  28. What does the '==' operator compare in Java?
    Primitive values or object references. Compares actual values for primitives, memory addresses for objects.
  29. What is the output of: System.out.println('Java' + (1 + 2));?
    Java3. Parentheses force addition first, then concatenation.
  30. What is the result of: System.out.println(10 / 3);?
    3. Integer division truncates the decimal portion in Java.
  31. How do you print a double quote in a string in Java?
    Using escape sequence \". Backslash escapes special characters in string literals.
  32. What is the operator precedence of *, /, %, +, - in Java?
    *, /, % have higher precedence than +, -. Multiplication, division, and modulus are evaluated before addition and subtraction.
  33. What will be printed: System.out.println('a' + 'b');?
    195. ASCII values: a=97, b=98, so 97+98=19597 + 98 = 195.
  34. What does the expression 5 + 3 * 2 evaluate to in Java?
    11. Multiplication has higher precedence than addition: 3×2=63 \times 2 = 6, then 5+6=115 + 6 = 11.
  35. Which data type can store a single character in Java?
    char. Stores a single Unicode character in 16 bits.

Study these flashcards