AP Computer Science a Flashcards: If Statements

Study If Statements in AP Computer Science a with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science a

If Statements

0 mastered0 still learning

0% Complete

QUESTION
1/ 74

What is the difference between '=' and '==' in Java?

Tap card or press Space to flip

ANSWER

'=' is assignment, '==' is equality check. Assignment stores a value, equality comparison tests for same value.

How well did you know it?

Card 1 / 74

What this deck covers

This deck focuses on If Statements, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science a.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

All flashcards

Flashcard 1: What is the difference between '=' and '==' in Java?

Answer: '=' is assignment, '==' is equality check. Assignment stores a value, equality comparison tests for same value.

Flashcard 2: Which logical operator represents 'OR' in Java?

Answer: ||. Double pipe requires at least one condition to be true.

Flashcard 3: What block executes if the condition is true? if (condition) { ... } else {...}

Answer: The first block executes. True conditions execute the if block, false conditions execute else.

Flashcard 4: What is the purpose of an if statement?

Answer: To execute code based on a condition. Allows conditional execution of code blocks based on boolean expressions.

Flashcard 5: What is the purpose of an if statement?

Answer: To execute code based on a condition. Allows conditional execution of code blocks based on boolean expressions.

Flashcard 6: Find and correct the error: if x = 10 { System.out.println("Ten"); }

Answer: if (x == 10) { System.out.println("Ten"); }. Use double equals for comparison, not single equals for assignment.

Flashcard 7: Identify the keyword used to introduce an if statement.

Answer: if. Reserved keyword that begins every conditional statement in Java.

Flashcard 8: What is the result of if (x >= 10) {...} with x = 9?

Answer: false. Nine is not greater than or equal to ten.

Flashcard 9: What is the outcome of this statement? if (true && false) { ... } else { ... }

Answer: The else block executes. AND operation with false makes entire condition false, triggering else.

Flashcard 10: Evaluate the condition: if (5 < 3) { ... }

Answer: false. Five is not less than three, so the condition evaluates to false.

Flashcard 11: What is the result of if (x < 0) {...} with x = -1?

Answer: true. Negative one is indeed less than zero.

Flashcard 12: What keyword is used to test multiple conditions?

Answer: else if. Allows chaining multiple conditions in sequence.

Flashcard 13: What is the outcome? if (false) { System.out.println("Yes"); } else { System.out.println("No"); }

Answer: No. False condition skips if block, so else block executes instead.

Flashcard 14: In an if-else ladder, when does the else execute?

Answer: When all conditions are false. Else serves as the default case when no if/else-if conditions match.

Flashcard 15: Which logical operator represents 'AND' in Java?

Answer: &&. Double ampersand requires both conditions to be true.

Flashcard 16: Find and correct the error: if x = 10 { System.out.println("Ten"); }

Answer: if (x == 10) { System.out.println("Ten"); }. Use double equals for comparison, not single equals for assignment.

Flashcard 17: Identify the keyword used for an alternative block in if statements.

Answer: else. Provides an alternative path when the if condition is false.

Flashcard 18: Identify the error in this code: if (x > 5) System.out.println(x); }

Answer: Remove the closing brace '}' after the statement. Single statements don't need braces, so the extra closing brace is invalid.

Flashcard 19: What is the syntax for an if statement in Java?

Answer: if (condition) { statements; }. Standard Java syntax with condition in parentheses and statements in braces.

Flashcard 20: What is the result of if (x < 0) {...} with x = -1?

Answer: true. Negative one is indeed less than zero.

Flashcard 21: What is the outcome of if (x < 5 && x > 10) {...} with x = 7?

Answer: false. Seven cannot be both less than five and greater than ten simultaneously.

Flashcard 22: Evaluate the condition: if (5 < 3) { ... }

Answer: false. Five is not less than three, so the condition evaluates to false.

Flashcard 23: What is the output if x = 5? if (x != 5) { System.out.println("No"); }

Answer: No output. Since x equals 5, the not-equal condition is false, so nothing prints.

Flashcard 24: Find and correct the error: if (x > 5); { System.out.println(x); }

Answer: Remove the semicolon ';' after the condition. Semicolon after condition creates empty statement, breaking the if structure.

Flashcard 25: What will execute if both conditions are false? if (false) {...} else if (false) {...} else {...}

Answer: The else block executes. When no previous conditions are true, else provides the default action.

Flashcard 26: What will this code print? if (3 != 3) { System.out.println("Yes"); } else { System.out.println("No"); }

Answer: No. Since 3 equals 3, the not-equal condition is false, executing else.

Flashcard 27: What is the condition to check for not equal to in Java?

Answer: !=. Exclamation equals tests for inequality between two values.

Flashcard 28: Find and correct the error: if (x > 5) { System.out.println("Yes") }

Answer: Add a semicolon ';' after "Yes". Missing semicolon after println statement causes compilation error.

Flashcard 29: Choose the correct syntax for an else block.

Answer: else { statements; }. Else block syntax follows the if block with statements in braces.

Flashcard 30: Choose the correct relational operator for equality.

Answer: ==. Double equals compares values for equality, unlike single equals for assignment.

Flashcard 31: What is the result of if (x == 0 && x > -1) {...} with x = 0?

Answer: true. Both x equals zero and x greater than negative one are true.

Flashcard 32: What is the output if x = 5? if (x > 3) { System.out.println("Yes"); }

Answer: Yes. Since 5 > 3 is true, the if block executes and prints.

Flashcard 33: What is the return type of a condition in an if statement?

Answer: boolean. Conditions must evaluate to either true or false.

Flashcard 34: Identify the error in this code: if (x > 5) System.out.println(x); }

Answer: Remove the closing brace '}' after the statement. Single statements don't need braces, so the extra closing brace is invalid.

Flashcard 35: What is the result of if (x >= 10) {...} with x = 9?

Answer: false. Nine is not greater than or equal to ten.

Flashcard 36: What does the following print? if (true || false) { System.out.println("A"); }

Answer: A. OR operation with true makes entire condition true, executing if block.

Flashcard 37: What is the difference between '=' and '==' in Java?

Answer: '=' is assignment, '==' is equality check. Assignment stores a value, equality comparison tests for same value.

Flashcard 38: What is the result if x = 8? if (x == 10) { System.out.println("Yes"); } else { System.out.println("No"); }

Answer: No. Since 8 ≠ 10, the condition is false and else block executes.

Flashcard 39: Identify the keyword used to introduce an if statement.

Answer: if. Reserved keyword that begins every conditional statement in Java.

Flashcard 40: Identify the keyword used for an alternative block in if statements.

Answer: else. Provides an alternative path when the if condition is false.

Flashcard 41: What is the outcome of if (x < 5 && x > 10) {...} with x = 7?

Answer: false. Seven cannot be both less than five and greater than ten simultaneously.

Flashcard 42: What is the output if x = 5? if (x != 5) { System.out.println("No"); }

Answer: No output. Since x equals 5, the not-equal condition is false, so nothing prints.

Flashcard 43: What will be the output? if (true) { System.out.println("Hello"); }

Answer: Hello. The condition true always executes the if block.

Flashcard 44: Evaluate: if (x == 5 || x == 10) {...} with x = 5.

Answer: true. OR condition is true when x equals either 5 or 10.

Flashcard 45: Choose the correct syntax for an else block.

Answer: else { statements; }. Else block syntax follows the if block with statements in braces.

Flashcard 46: In an if-else ladder, when does the else execute?

Answer: When all conditions are false. Else serves as the default case when no if/else-if conditions match.

Flashcard 47: What is the return type of a condition in an if statement?

Answer: boolean. Conditions must evaluate to either true or false.

Flashcard 48: Find and correct the error: if (x > 5); { System.out.println(x); }

Answer: Remove the semicolon ';' after the condition. Semicolon after condition creates empty statement, breaking the if structure.

Flashcard 49: What will this code print? if (3 != 3) { System.out.println("Yes"); } else { System.out.println("No"); }

Answer: No. Since 3 equals 3, the not-equal condition is false, executing else.

Flashcard 50: What will execute if both conditions are false? if (false) {...} else if (false) {...} else {...}

Answer: The else block executes. When no previous conditions are true, else provides the default action.

Flashcard 51: What keyword follows an if block when no condition is specified?

Answer: else. Else provides the alternative when the if condition fails.

Flashcard 52: Find and correct the error: if (x > 5) { System.out.println("Yes") }

Answer: Add a semicolon ';' after "Yes". Missing semicolon after println statement causes compilation error.

Flashcard 53: What is the result if x = 8? if (x == 10) { System.out.println("Yes"); } else { System.out.println("No"); }

Answer: No. Since 8 ≠ 10, the condition is false and else block executes.

Flashcard 54: What is the syntax for an if statement in Java?

Answer: if (condition) { statements; }. Standard Java syntax with condition in parentheses and statements in braces.

Flashcard 55: What is the output if y = 0? if (y) { System.out.println("Yes"); }

Answer: Compilation error. Integer variables cannot be used directly as boolean conditions in Java.

Flashcard 56: What block executes if the condition is true? if (condition) { ... } else {...}

Answer: The first block executes. True conditions execute the if block, false conditions execute else.

Flashcard 57: Choose the correct relational operator for equality.

Answer: ==. Double equals compares values for equality, unlike single equals for assignment.

Flashcard 58: What is the result of if (x <= 10) {...} with x = 10?

Answer: true. Less than or equal includes equality, so 10 ≤ 10 is true.

Flashcard 59: What is the outcome? if (false) { System.out.println("Yes"); } else { System.out.println("No"); }

Answer: No. False condition skips if block, so else block executes instead.

Flashcard 60: Which logical operator represents 'AND' in Java?

Answer: &&. Double ampersand requires both conditions to be true.

Flashcard 61: What keyword is used to test multiple conditions?

Answer: else if. Allows chaining multiple conditions in sequence.

Flashcard 62: Which logical operator represents 'OR' in Java?

Answer: ||. Double pipe requires at least one condition to be true.

Flashcard 63: Choose the correct syntax for else if block.

Answer: else if (condition) { statements; }. Else if combines else and if to test additional conditions sequentially.

Flashcard 64: What is the output if x = 5? if (x > 3) { System.out.println("Yes"); }

Answer: Yes. Since 5 > 3 is true, the if block executes and prints.

Flashcard 65: What keyword follows an if block when no condition is specified?

Answer: else. Else provides the alternative when the if condition fails.

Flashcard 66: What is the outcome of this statement? if (true && false) { ... } else { ... }

Answer: The else block executes. AND operation with false makes entire condition false, triggering else.

Flashcard 67: What is the output if y = 0? if (y) { System.out.println("Yes"); }

Answer: Compilation error. Integer variables cannot be used directly as boolean conditions in Java.

Flashcard 68: What is the result of if (x <= 10) {...} with x = 10?

Answer: true. Less than or equal includes equality, so 10 ≤ 10 is true.

Flashcard 69: Evaluate: if (x == 5 || x == 10) {...} with x = 5.

Answer: true. OR condition is true when x equals either 5 or 10.

Flashcard 70: Choose the correct syntax for else if block.

Answer: else if (condition) { statements; }. Else if combines else and if to test additional conditions sequentially.

Flashcard 71: What does the following print? if (true || false) { System.out.println("A"); }

Answer: A. OR operation with true makes entire condition true, executing if block.

Flashcard 72: What will be the output? if (true) { System.out.println("Hello"); }

Answer: Hello. The condition true always executes the if block.

Flashcard 73: What is the result of if (x == 0 && x > -1) {...} with x = 0?

Answer: true. Both x equals zero and x greater than negative one are true.

Flashcard 74: What is the condition to check for not equal to in Java?

Answer: !=. Exclamation equals tests for inequality between two values.