zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcardStudy GuideStudy GuideQuestion BankQuestion Bank
GlossaryGlossary

Boolean Logic & Conditional Statements

Question 1
Computer Science AAPConcept Practice
1 mark

What is the correct syntax for a basic if-else if-else statement in Java?

Question 2
Computer Science AAPConcept Practice
1 mark

In an if-else if-else statement, what happens if multiple conditions evaluate to true?

Question 3
Computer Science AAPConcept Practice
1 mark

Given the following scenario: A program needs to determine if a number is positive, negative, or zero. Which if-else if-else statement would be most appropriate?

Question 4
Computer Science AAPConcept Practice
1 mark

Consider the following code snippet:

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

What will be printed to the console?

Question 5
Computer Science AAPConcept Practice
1 mark

You are writing a program to categorize students based on their age. The categories are: Child (0-12), Teen (13-19), and Adult (20+). Which order of conditions in an if-else if-else statement is most efficient and correct?

Question 6
Computer Science AAPConcept Practice
1 mark

What is the most likely outcome of the following code snippet?

java
int x = 7;
if (x > 10)
    System.out.println("A");
else if (x > 5)
    System.out.println("B");
else
    System.out.println("C");
Question 7
Computer Science AAPConcept Practice
1 mark

Consider the following code:

java
int num = 15;
if (num % 5 == 0) {
    System.out.println("Divisible by 5");
} else if (num % 3 == 0) {
    System.out.println("Divisible by 3");
} else {
    System.out.println("Not divisible by 3 or 5");
}

What is the output of this code?

Feedback stars icon

How are we doing?

Give us your feedback and let us know how we can improve

Question 8
Computer Science AAPConcept Practice
1 mark

Given the following code, complete the determineSign method so that it returns "Positive" if the number is greater than 0, "Negative" if it's less than 0, and "Zero" if it's equal to 0. ``` java public static String determineSign(int num) { // Your code here }

Question 9
Computer Science AAPConcept Practice
1 mark

Write a method called getLetterGrade that accepts an integer score and returns a letter grade according to the following scale:

  • 90-100: 'A'
  • 80-89: 'B'
  • 70-79: 'C'
  • 60-69: 'D'
  • 0-59: 'F'

Which of the following implementations is correct?