1.
Even or Odd Number Checker
public class EvenOddChecker {
public static void main(String[] args) {
int number = 10;
if (number % 2 == 0) {
System.out.println(number + " is even");
} else {
System.out.println(number + " is odd");
}
}
}
2.Positive, Negative, or Zero
public class NumberSignChecker {
public static void main(String[] args) {
int number = 0;
if (number > 0) {
System.out.println("Number is positive.");
} else if (number < 0) {
System.out.println("Number is negative.");
} else {
System.out.println("Number is zero.");
}
}
}
3.Age Eligibility for Voting
public class VotingEligibility {
public static void main(String[] args) {
int age = 17;
if (age >= 18) {
System.out.println("Eligible to vote.");
} else {
System.out.println("Not eligible to vote.");
}
}
}
4. Leap Year Checker
public class LeapYearChecker {
public static void main(String[] args) {
int year = 2000;
boolean isLeapYear = false;
if (year % 4 == 0) {
isLeapYear = true;
if (year % 100 == 0 && year % 400 != 0) {
isLeapYear = false;
}
}
if (isLeapYear) {
System.out.println(year + " is a leap year");
} else {
System.out.println(year + " is not a leap year");
}
}
}
5. Java Program: Find Largest of Three Numbers
public class LargestNumber {
public static void main(String[] args) {
int num1 = 10, num2 = 20, num3 = 7;
if (num1 >= num2 && num1 >= num3) {
System.out.println(num1 + " is the largest number.");
} else if (num2 >= num1 && num2 >= num3) {
System.out.println(num2 + " is the largest number.");
} else {
System.out.println(num3 + " is the largest number.");
}
}
}