0% found this document useful (0 votes)
8 views2 pages

Public Class ConditionalStatements

The document contains a Java program that demonstrates the use of conditional statements, including if-else, nested if, and switch statements. It checks whether a number is positive, negative, or zero, and determines if it is even or odd. Additionally, it maps a numeric day of the week to its corresponding name using a switch statement.

Uploaded by

utkarshraw45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Public Class ConditionalStatements

The document contains a Java program that demonstrates the use of conditional statements, including if-else, nested if, and switch statements. It checks whether a number is positive, negative, or zero, and determines if it is even or odd. Additionally, it maps a numeric day of the week to its corresponding name using a switch statement.

Uploaded by

utkarshraw45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

public class ConditionalStatements {

public static void main(String[] args) {

int number = 25;

// Using if, else if, and else

if (number > 0) {

System.out.println(number + " is a positive number.");

} else if (number < 0) {

System.out.println(number + " is a negative number.");

} else {

System.out.println(number + " is zero.");

// Using nested if

if (number != 0) {

if (number % 2 == 0) {

System.out.println(number + " is an even number.");

} else {

System.out.println(number + " is an odd number.");

// Using switch statement

int dayOfWeek = 3;

String dayName;

switch (dayOfWeek) {

case 1:

dayName = "Sunday";

break;

case 2:
dayName = "Monday";

break;

case 3:

dayName = "Tuesday";

break;

case 4:

dayName = "Wednesday";

break;

case 5:

dayName = "Thursday";

break;

case 6:

dayName = "Friday";

break;

case 7:

dayName = "Saturday";

break;

default:

dayName = "Invalid day";

break;

System.out.println("Day of the week is: " + dayName);

You might also like