Advanced Placement Computer Science A focusing on Java programming and object-oriented design.
Programs often need to make choices and repeat actions. Java's control structures—if statements, loops, and logic operators—let you manage the flow of your programs.
Use if
to run code only under certain conditions.
if (score >= 90) {
System.out.println("Great job! You got an A!");
} else {
System.out.println("Keep trying!");
}
for (int i = 0; i < 5; i++) {
System.out.println("Count: " + i);
}
int count = 0;
while (count < 5) {
System.out.println("Count: " + count);
count++;
}
Combine conditions using logical operators (&&
, ||
, !
) to make your programs smarter.
Control structures help apps make decisions: social media filters posts, games check for winning conditions, and robots follow instructions.
Using a loop to print all even numbers from 1 to 100.
Checking if a password is correct before allowing access.
Control structures let your programs make decisions and repeat tasks, making them flexible and powerful.