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