professor-curious-logo
professor-curious-logo
  1. AP Computer Science A
FlashcardFlashcard
Study GuideStudy GuideQuestion BankQuestion BankGlossaryGlossary

What does the following code output?

java
int x = 5;
if (x > 10) {
 System.out.println("A");
} else if (x > 5 || x < 10) {
 System.out.println("B");
} else {
 System.out.println("C");
}

B

Flip to see [answer/question]
Flip to see [answer/question]
Revise later
SpaceTo flip
If confident

All Flashcards

What does the following code output?

java
int x = 5;
if (x > 10) {
 System.out.println("A");
} else if (x > 5 || x < 10) {
 System.out.println("B");
} else {
 System.out.println("C");
}

B

Complete the following code snippet to check if a number is positive and even:

java
int num = 10;
if (/* FILL IN */) {
 System.out.println("Positive Even");
}

num > 0 && num % 2 == 0

What does the following code output?

java
boolean a = true;
boolean b = false;
System.out.println(a || b && !a);

true

What does the following code output?

java
int x = 7;
if (x % 2 == 0 && x > 5) {
 System.out.println("Even and Greater than 5");
} else {
 System.out.println("Not both conditions met");
}

Not both conditions met

What does the following code output?

java
int year = 2000;
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
 System.out.println("Leap Year");
} else {
 System.out.println("Not a Leap Year");
}

Leap Year

What does the following code output?

java
int age = 15;
if (age >= 16 && age <= 18) {
 System.out.println("Teenager");
} else {
 System.out.println("Not a Teenager");
}

Not a Teenager

What does the following code output?

java
int temp = 25;
boolean isRaining = false;
if (temp > 20 || isRaining) {
 System.out.println("Enjoy the weather");
} else {
 System.out.println("Stay inside");
}

Enjoy the weather

What does the following code output?

java
int score = 85;
if (!(score < 70)) {
 System.out.println("Passed");
} else {
 System.out.println("Failed");
}

Passed

What does the following code output?

java
int num1 = 10;
int num2 = 5;
if (num1 > 0 && num2 > 0 && num1 > num2) {
 System.out.println("Num1 is greater and both are positive");
}

Num1 is greater and both are positive

What does the following code output?

java
int value = -5;
if (value > 0 || value % 2 == 0) {
 System.out.println("Condition met");
} else {
 System.out.println("Condition not met");
}

Condition met

What is the difference between nested if and compound conditional?

Nested if: if statements within if statements. Compound: Combining conditions with logical operators.

Compare && and || operators.

&&: Both conditions must be true. ||: At least one condition must be true.

Compare if and else if statements.

if: First condition checked. else if: Checked only if previous if conditions are false.

Compare if and else statements.

if: Executes if condition is true. else: Executes if if condition is false.

Compare using multiple nested if statements vs using a single compound conditional.

Nested if: Can be harder to read. Compound conditional: More concise and readable.

What is the difference between using ! and not using !?

!: Reverses the boolean value. Not using !: Checks the original boolean value.

Compare using && and using nested if statements for the same condition.

&&: More concise. Nested if: Can be more verbose but sometimes clearer.

Compare using || and using multiple if statements for the same condition.

||: More concise. Multiple if: Can be more verbose but sometimes clearer.

Compare the order of operations when using && and || without parentheses.

&& has higher precedence than ||, so && is evaluated first.

Compare the readability of nested if statements with deep nesting vs shallow nesting.

Deep nesting: Harder to read and understand. Shallow nesting: Easier to read and understand.

Why is indentation important in nested conditionals?

Improves readability and debugging.

What is the order of operations for boolean operators?

NOT, AND, OR.

What is the benefit of using compound conditionals?

Readability, maintainability, and sometimes efficiency.

How do nested conditionals work?

Outer if condition is checked first. If true, the inner if condition is evaluated. If false, the inner condition is skipped.

Why simplify complex nested if statements on exams?

Saves time and reduces errors.

What is the result of 'true || false'?

true

What is the result of '!true && false'?

false

What is the result of '!(true && false)'?

true

What is the result of 'false || (true && false)'?

false

What is the result of 'true && !false'?

true