int x = 5;
if (x > 3) {
System.out.println("A");
} else {
System.out.println("B");
}
A
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Flip
Revise later
SpaceTo flip
If confident
All Flashcards
What does the following code output?
```java
int x = 5;
if (x > 3) {
System.out.println("A");
} else {
System.out.println("B");
}
```
`A`
What does the following code output?
```java
int x = 10;
if (x < 5 && x > 7) {
System.out.println("True");
} else {
System.out.println("False");
}
```
`False`
What does the following code output?
```java
String str1 = "hello";
String str2 = new String("hello");
if (str1.equals(str2)) {
System.out.println("Equal");
} else {
System.out.println("Not Equal");
}
```
`Equal`
What does the following code output?
```java
boolean a = true;
boolean b = false;
System.out.println(!a || b);
```
`false`
Identify the error in the following code:
```java
if (x = 5) {
System.out.println("x is 5");
}
```
The condition should use `==` for comparison, not `=` for assignment. It should be `if (x == 5)`.
What does the following code output?
```java
int score = 75;
if (score >= 90) {
System.out.println("A");
} else if (score >= 80) {
System.out.println("B");
} else if (score >= 70) {
System.out.println("C");
} else {
System.out.println("D");
}
```
`C`
What does the following code output?
```java
int num = 6;
if (num % 2 == 0 && num % 3 == 0) {
System.out.println("Divisible by 2 and 3");
} else {
System.out.println("Not divisible by 2 and 3");
}
```
`Divisible by 2 and 3`
What does the following code output?
```java
int age = 20;
String message = (age >= 18) ? "Adult" : "Minor";
System.out.println(message);
```
`Adult`
What does the following code output?
```java
String s1 = new String("Java");
String s2 = new String("Java");
System.out.println(s1 == s2);
```
`false`
What does the following code output?
```java
boolean x = false, y = true;
if (x = y) {
System.out.println("True");
} else {
System.out.println("False");
}
```
`True`
What is a Boolean expression?
An expression that evaluates to either `true` or `false`.
What is an `if` statement?
A conditional statement that executes a block of code only if a condition is `true`.
What is an `if-else` statement?
A conditional statement that executes one block of code if a condition is `true`, and another block if it's `false`.
What is an `if-else if-else` statement?
A conditional statement that creates multiple branches, allowing you to check a series of conditions.
What is the `==` operator?
Checks if two primitive values are equal.
What is the `!=` operator?
Checks if two values are not equal.
What is the `&&` operator?
The AND operator. Returns `true` only if both operands are `true`.
What is the `||` operator?
The OR operator. Returns `true` if at least one operand is `true`.
What is the `!` operator?
The NOT operator. Negates a boolean value.
What does `.equals()` do?
Compares the content of objects for equality.
How are boolean expressions and conditional statements used in validating user input?
They are used to check if the input meets certain criteria (e.g., is within a valid range, is of the correct format) before processing it.
How are conditional statements used in game development?
To control game logic, such as character movement, collision detection, and scoring.
How are boolean expressions and conditional statements used in decision-making systems?
They are used to evaluate different options and select the best course of action based on predefined rules.
How are conditional statements used in controlling access to resources?
They are used to check user permissions and grant or deny access based on their roles and privileges.
How are boolean expressions used in search algorithms?
To filter results based on specific criteria, such as keywords, date ranges, or file types.
How are conditional statements used in automated systems?
To make decisions based on sensor data or other inputs, such as adjusting temperature, activating alarms, or controlling machinery.
How are boolean expressions used in data analysis?
To filter and categorize data based on specific conditions, such as identifying outliers or grouping similar data points.
How are conditional statements used in web applications?
To handle different user interactions, display different content based on user roles, and control navigation.
How are boolean expressions used in AI and machine learning?
To create decision trees and other models that classify data based on specific features.
How are conditional statements used in financial modeling?
To simulate different scenarios and predict outcomes based on various economic conditions.