1/14
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Q: What is a conditional statement in Java?
A conditional statement is used to perform different actions based on different conditions, such as if, else if, and else.
Q: What is the syntax of an "if" statement in Java?
if (condition) { // code to execute if condition is true }
Q: What is the purpose of an "else" statement?
The "else" statement is used to execute a block of code when the "if" condition is false.
Q: What is an "else if" statement?
It allows testing multiple conditions in sequence when the initial "if" condition is false.
Q: What is the difference between "if" and "switch" statements in Java?
"if" is used for evaluating complex conditions, whereas "switch" is more efficient for checking a variable against many possible values.
Q: What is a "switch" statement?
A "switch" statement allows a variable to be tested for equality against a list of values (cases).
Q: What are logical operators used in conditional statements?
&& (AND), || (OR), ! (NOT)
Q: What is a loop in Java?
A loop allows a block of code to be executed repeatedly based on a condition, like "for", "while", or "do-while".
Q: What is the difference between a "for" loop and a "while" loop in Java?
A "for" loop is generally used when the number of iterations is known, while a "while" loop is used when the number of iterations is unknown.
Q: What is the syntax of a "for" loop in Java?
for (initialization; condition; update) { // code to execute }
Q: What is a "while" loop?
A "while" loop executes a block of code as long as the given condition is true.
Q: What is a "do-while" loop?
A "do-while" loop executes the block of code at least once before checking the condition.
Q: What is the "break" statement in Java?
The "break" statement is used to exit a loop or switch statement prematurely.
Q: What is the "continue" statement in Java?
The "continue" statement skips the current iteration of a loop and proceeds to the next iteration.