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
num
is positive, negative, or zero using if-else statements.Create a Java program to determine whether a given year
year
is a leap year or not using if-else statements.Write a Java program to find the maximum of three numbers
a
,b
, andc
using if-else statements.Develop a Java program to check if a given character
ch
is a vowel or a consonant using if-else statements.Implement a Java program to check if a given number
num
is even or odd using if-else statements.Write a Java program to determine the grade of a student based on their percentage
percentage
using if-else statements.Create a Java program to find the largest among three numbers
num1
,num2
, andnum3
using if-else statements.Develop a Java program to determine if a given integer
number
is divisible by both 2 and 3 using if-else statements.Write a Java program to check if a given string
str
is 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
month
using 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
quantity
items atprice
each, 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
age
using if-else statements.Develop a Java program to calculate the discount percentage based on the total purchase amount
totalAmount
using if-else statements.Create a Java program to determine the season based on a given month
month
using switch statements.Implement a Java program to calculate the BMI (Body Mass Index) based on the weight
weight
in kilograms and heightheight
in meters using if-else statements.Write a Java program to determine the largest among three numbers
x
,y
, andz
using nested if-else statements.Develop a Java program to assign a grade to a student based on their marks
marks
in 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