Complete the code to check if a number is positive.
int num = 10; if (num [1] 0) { System.out.println("Positive number"); }
The condition num > 0 checks if the number is positive.
Complete the else-if ladder to check if a number is zero.
int num = 0; if (num > 0) { System.out.println("Positive number"); } else if (num [1] 0) { System.out.println("Zero"); } else { System.out.println("Negative number"); }
The condition num == 0 checks if the number is exactly zero.
Fix the error in the else-if ladder condition to check if a number is negative.
int num = -5; if (num > 0) { System.out.println("Positive number"); } else if (num [1] 0) { System.out.println("Negative number"); } else { System.out.println("Zero"); }
The condition num < 0 checks if the number is negative. The else block handles zero.
Fill both blanks to complete the else-if ladder that prints the size category based on age.
int age = 20; if (age [1] 12) { System.out.println("Child"); } else if (age [2] 19) { System.out.println("Teenager"); } else { System.out.println("Adult"); }
The first condition checks if age is 12 or less (child). The second checks if age is less than 19 (teenager). Otherwise, adult.
Fill all three blanks to complete the else-if ladder that categorizes temperature.
int temp = 30; if (temp [1] 0) { System.out.println("Freezing"); } else if (temp [2] 30) { System.out.println("Cold"); } else if (temp [3] 60) { System.out.println("Warm"); } else { System.out.println("Hot"); }
The first condition checks if temp is 0 or below (freezing). The second checks if temp is less than 30 (cold). The third checks if temp is greater than 60 (warm). The else covers hot temperatures from 30 to 60.