💎Common If Statements

Here's a list of common if statements that are often used in interviews:

Check if a number is positive or negative:

int number = 10;
if (number > 0) {
    // Code block for positive number
} else if (number < 0) {
    // Code block for negative number
} else {
    // Code block for zero
}

Check if a number is even or odd:

int number = 7;
if (number % 2 == 0) {
    // Code block for even number
} else {
    // Code block for odd number
}

Check if a number is between a range:

Check if a character is a vowel or consonant:

Check if a string is empty or not:

Check if an array is empty or not:

Check if a condition is true or false:

Check if a reference is null or not:

Check if two objects are equal or not:

Check if a condition is true, false, or unknown:

Check if a string contains a specific substring:

Check if a number is divisible by another number:

Check if a number is within a specific range:

Check if a character is uppercase or lowercase:

Check if an object is an instance of a specific class:

Check if an array contains a specific element:

Check if a file exists:

Check if a condition is false:

Check if a string starts or ends with a specific substring:

Check if a number is zero or non-zero:

Last updated

Was this helpful?