Control Statements
Let's test your knowledge on if-else and switch statements in Java with the following problem statements:
Write a Java program to check if a given number
numis positive, negative, or zero using if-else statements.Create a Java program to determine whether a given year
yearis a leap year or not using if-else statements.Write a Java program to find the maximum of three numbers
a,b, andcusing if-else statements.Develop a Java program to check if a given character
chis a vowel or a consonant using if-else statements.Implement a Java program to check if a given number
numis even or odd using if-else statements.Write a Java program to determine the grade of a student based on their percentage
percentageusing if-else statements.Create a Java program to find the largest among three numbers
num1,num2, andnum3using if-else statements.Develop a Java program to determine if a given integer
numberis divisible by both 2 and 3 using if-else statements.Write a Java program to check if a given string
stris palindrome or not using if-else statements.Implement a Java program to determine the day of the week based on a given number
dayNumber(1 for Monday, 2 for Tuesday, etc.) using switch statements.Develop a Java program to print the name of the month based on a given number
monthNumber(1 for January, 2 for February, etc.) using switch statements.Write a Java program to calculate the number of days in a given month
monthusing switch statements.Create a Java program to print the name of a shape based on a given number
shapeNumber(1 for Circle, 2 for Square, 3 for Triangle, etc.) using switch statements.Implement a Java program to calculate the total cost of purchasing
quantityitems atpriceeach, including a sales tax of 8%, using if-else statements.Write a Java program to determine the eligibility of a person to vote based on their age
ageusing if-else statements.Develop a Java program to calculate the discount percentage based on the total purchase amount
totalAmountusing if-else statements.Create a Java program to determine the season based on a given month
monthusing switch statements.Implement a Java program to calculate the BMI (Body Mass Index) based on the weight
weightin kilograms and heightheightin meters using if-else statements.Write a Java program to determine the largest among three numbers
x,y, andzusing nested if-else statements.Develop a Java program to assign a grade to a student based on their marks
marksin a subject using if-else statements.
These problems cover various scenarios where you'll need to use if-else and switch statements in Java to solve different types of problems.
Last updated
Was this helpful?