Module 2: Conditional Programs
Java programs that use if-else, nested if, and switch-case to make decisions based on conditions.
20 program solutions
Program Solutions
Grade Calculator
Calculate grade based on percentage using conditional statements.
Vowel or Consonant
Check whether a character is a vowel or a consonant.
Check Alphabet/Digit/Special Character
Check whether a character is an alphabet, digit, or special character.
Check Leap Year
Check whether a given year is a leap year.
Check Armstrong Number
Check whether a number is an Armstrong number (sum of digits^number-of-digits equals the number).
Check Perfect Number
Check whether a number is a perfect number (sum of proper divisors equals the number).
Check Strong Number
Check whether a number is a strong number (sum of factorials of digits equals the number).
Check Palindrome Number
Check whether a number is a palindrome (same forwards and backwards).
Max of 3 Using Nested If
Find the maximum of three numbers using nested if statements.
Electricity Bill Calculator
Calculate electricity bill based on units consumed using slab rates.
Menu-Driven Calculator
Implement a simple calculator using switch-case based on user choice.
Profit or Loss
Determine profit or loss based on cost price and selling price.
Triangle Validity Check
Check if three sides can form a valid triangle using triangle inequality.
Roots of Quadratic Equation
Find the roots of a quadratic equation ax^2 + bx + c = 0 using discriminant.
Person Eligibility (Age Check)
Check if a person is eligible to vote based on age.
Library Fine Calculation
Calculate library fine based on number of days a book is overdue.
Attendance Percentage Calculator
Calculate attendance percentage and decide if a student is allowed to sit in exam.
Temperature Classification
Classify temperature as cold, moderate, or hot using conditions.
Discount Calculator
Apply discount based on purchase amount using conditional logic.
Basic Authentication Program
Check username and password against hardcoded values.