Complete the code to check if a number is positive.
int number = 10; if ([1] > 0) { System.out.println("Positive number"); }
The variable number holds the value to check. Using number in the if condition correctly tests if it is positive.
Complete the code to check if a number is positive and even.
int number = 8; if (number > 0) { if (number [1] 2 == 0) { System.out.println("Positive even number"); } }
The modulus operator % checks the remainder. If number % 2 == 0, the number is even.
Fix the error in the nested if statement to check if a number is positive and less than 100.
int number = 50; if (number > 0) { if (number [1] 100) { System.out.println("Number is positive and less than 100"); } }
The condition should check if number is less than 100, so the operator < is correct.
Fill both blanks to check if a number is between 10 and 20 (inclusive).
int number = 15; if (number [1] 10 && number [2] 20) { System.out.println("Number is between 10 and 20"); }
The number should be greater than or equal to 10 and less than or equal to 20, so use >= and <=.
Fill both blanks to print messages based on nested if conditions for age and score.
int age = 20; int score = 85; if (age [1] 18) { if (score [2] 80) { System.out.println("Adult with high score"); } else { System.out.println("Adult with low score"); } } else { System.out.println("Not an adult"); }
> instead of >= for age.<= instead of > for score.The first condition checks if age is at least 18 (>=), the second if score is greater than 80 (>), and the else covers the rest.