AP CSA boolean and if key terms

Study key concepts related to boolean logic and conditional statements in AP Computer Science A.

FoxBen6·26 fiches·14 questions·2 vues
APcomputer_scienceprogramming
0
Je sais
1 / 26
0
J'apprends
Recto

What is a boolean value?

Appuyez pour retourner
Verso

A binary value, either true or false.

Appuyez pour retourner
Je sais
J'apprends

Quiz(14 questions)

Question 1 sur 14

1. What is the result of false || true?

Termes dans ce set(26)

What is a boolean value?

A binary value, either true or false.

True or false: Boolean values can hold more than two states.

False, because boolean only represents true or false.

Difference between && and || operators?

&& is logical AND; || is logical OR.

Fill in the blank: The expression !(A && B) is equivalent to _____

(!A || !B) - De Morgan's Law.

What does the if statement do?

Executes a block of code if its condition is true.

True or false: An else statement is mandatory in an if-else structure.

False, it is optional.

What is a conditional expression?

An expression that evaluates to true or false.

What does the term 'short-circuit evaluation' refer to?

Stopping evaluation as soon as the result is determined.

Comparison: if vs. switch statement

Use if for conditions; switch for discrete values.

What is a nested if statement?

An if statement inside another if statement.

Fill in the blank: The operator == checks for _____

Equality between two values.

True or false: Boolean expressions can only compare numbers.

False, they can compare any data types.

What is the result of true && false?

The result is false.

What does the expression A || B evaluate to?

True if either A or B is true.

Difference between == and ===?

== checks value, === checks value and type.

What is the purpose of the else if statement?

To test multiple conditions in an if structure.

Fill in the blank: In Java, boolean variables can be declared as _____

boolean variableName; (e.g., boolean isTrue;)

True or false: Logical operators can combine boolean expressions.

True, they can combine multiple conditions.

What does the statement 'if (x > 10)' do?

Checks if x is greater than 10.

What is the default condition if no else is provided?

No action is taken if the if condition is false.

Fill in the blank: The expression (x < 5) || (x > 10) means x is _____

Less than 5 or greater than 10.

What does the 'break' statement do in a switch case?

Exits the switch structure immediately.

True or false: You can use boolean expressions in while loops.

True, they control loop execution.

What is the purpose of 'return' in a boolean function?

To return a boolean value from the function.

Definition of 'truth table'.

A table showing all possible truth values of logical expressions.

What does 'A != B' check?

It checks if A is not equal to B.

Questions dans ce set(14)

1. What is the result of false || true?

A.True
B.False
C.Undefined
D.Null

2. Which operator is used for logical AND?

A.&&
B.||
C.!
D.~

3. Which statement is used for multiple conditions?

A.if
B.switch
C.while
D.for

4. What happens if x is 10 in 'if (x < 10)'?

A.The code runs
B.The code doesn't run
C.An error occurs
D.None of the above

5. Which is NOT a boolean operator?

A.&&
B.||
C.==
D.!

6. What is the output of 'if (x == 5) { return true; }' when x is 3?

A.true
B.false
C.null
D.undefined

7. Which keyword is used to exit a loop or switch statement?

A.exit
B.stop
C.break
D.continue

8. What is the purpose of the else clause in an if-statement?

A.To repeat code
B.To catch exceptions
C.To run code if the if condition is false
D.To initialize variables

9. Which of the following is a valid boolean expression?

A.5 > 3
B.3 == 3
C.x != 0
D.All of the above

10. True or false: The expression !(A || B) is equivalent to !A && !B.

A.True
B.False
C.Depends on A and B
D.None of the above

11. What does x && y evaluate to if x is false?

A.true
B.false
C.undefined
D.value of y

12. In a switch statement, what happens if no case matches?

A.The program crashes
B.The default case runs
C.The switch statement does nothing
D.An error is thrown

13. Which operator checks for both value and type equality?

A.==
B.===
C.!==
D.!=

14. What is the outcome of the expression 'x < 5 && x > 10'?

A.True
B.False
C.Error
D.Undefined

Sets associés

Créez votre propre set d'étude

Téléchargez un PDF, collez vos notes ou décrivez un sujet – l'IA génère des fiches, des quiz et plus en quelques secondes.

Mis en avant sur