1/51
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
What are boolean variables used for in programming?
To compare two values and represent the result as true or false.
What is the purpose of relational operators in Java?
To compare two values and return a boolean result.
List the six relational operators in Java.
What does the operator '==' signify?
It checks if two values are equal.
What is the syntax for a one-way if statement?
if (boolean-expression) { statement(s); }
Provide an example of a one-way if statement.
if (radius >= 0) { area = radius * radius * PI; }
What is the structure of a two-way if statement?
if (boolean-expression) { statement(s)-for-true-case; } else { statement(s)-for-false-case; }
How does a multi-way if-else statement operate?
It checks multiple conditions in sequence until one is true.
What is a common mistake when using if statements?
Adding a semicolon at the end of an if clause.
What is the purpose of logical operators?
To combine multiple boolean expressions.
List the logical operators in Java.
! (not), && (and), || (or), ^ (exclusive or)
What does the '&&' operator represent?
Logical conjunction; it returns true if both operands are true.
What does the '||' operator represent?
Logical disjunction; it returns true if at least one operand is true.
What is the purpose of the switch statement?
To execute different parts of code based on the value of a variable.
What is a common technique to debug errors in if statements?
Trace through the conditions and check the flow of execution.
What is the conditional expression syntax in Java?
condition ? expressionIfTrue : expressionIfFalse
What is the result of the expression '!(age > 18)' if age is 24?
false, because (age > 18) is true.
What happens if the condition in an if statement is false?
The statements inside the if block are skipped.
How can you compute taxes based on filing status in Java?
Using a series of if-else statements to check the filing status.
What is the result of 'radius < 0' if radius is 5?
false
What does the operator '!=' signify?
It checks if two values are not equal.
What is the output of the following code if score is 70.0? if (score >= 70.0) System.out.print('C');
'C'
What is the significance of operator precedence?
It determines the order in which operations are performed in expressions.
What is the output of 'System.out.print("A");' if score is 95.0?
'A', because the condition score >= 90.0 is true.
What does the 'else' clause match in an if-else statement?
The most recent if clause in the same block.
What is the output of 'System.out.println("Negative input");' if radius is -1?
'Negative input'
What does the operator '||' represent?
'||' represents the logical OR operator.
What is the result of (age > 34) || (weight <= 140) when age is 24 and weight is 140?
True, because (age > 34) is false and (weight <= 140) is true.
What does the operator '^' represent?
'^' represents the logical XOR (exclusive OR) operator.
What is the result of (age > 14) ^ (weight > 140) when age is 24 and weight is 140?
True, because (age > 14) is true and (weight > 140) is false.
What does the '&&' operator do?
'&&' represents the logical AND operator.
What is the output of the expression (number % 2 == 0) && (number % 3 == 0)?
It checks if the number is divisible by both 2 and 3.
What data types can the switch expression yield?
char, byte, short, or int.
What happens if a break statement is omitted in a switch case?
The next case statement will be executed (fall-through behavior).
What is the syntax for a switch statement?
switch (expression) { case value1: statements; break; … default: statements; }
What is a conditional expression in Java?
An expression that evaluates to one of two values based on a boolean condition, using the ternary operator.
How is the ternary operator structured?
boolean-expression ? expression1 : expression2.
What is operator precedence?
The rules that determine the order in which operators are evaluated in an expression.
What is the order of operations for the following operators: *, /, +, -?
Multiplication and division are evaluated before addition and subtraction.
What is the associativity of binary operators?
Most binary operators are left-associative, meaning they are evaluated from left to right.
What is debugging?
The process of finding and correcting errors in a program.
What is a debugger?
A program that helps in debugging by allowing step-by-step execution and inspection of variables.
What is the purpose of using breakpoints in debugging?
To pause execution at a certain point to inspect the state of the program.
What is the output of the conditional expression if num is 4?
The output will be '4 is even'.
What does the expression (1 > x) && (1 > x++) do?
It evaluates whether 1 is greater than x and increments x if true.
What is the result of the expression 3 + 4 * 4 > 5 * (4 + 3) - 1?
False, as the evaluation results in 19 > 34.
What is the significance of parentheses in operator precedence?
Parentheses indicate which operations should be performed first.
What does the expression a = b += c = 5 mean?
It means b is assigned the value of c (5), and then a is assigned the value of b.
What is the role of print statements in debugging?
To display variable values and execution flow to help identify errors.
What is the output of the switch statement when day is 2?
It will print 'Weekday'.
What happens in a switch statement if no case matches?
The default case is executed if it exists.
What is the result of the expression (num % 2 == 0) ? num + ' is even' : num + ' is odd'?
It prints whether num is even or odd based on the condition.