KEMBAR78
Day4 Conditional+Statements | PDF | Numbers | Computer Programming
0% found this document useful (0 votes)
6 views5 pages

Day4 Conditional+Statements

The document provides an overview of Java conditional statements, including if, if..else, nested if, and switch statements, explaining their syntax and usage. It also includes lab assignments for each type of statement, prompting users to write programs that apply these concepts in various scenarios. The focus is on controlling program flow based on specific conditions.

Uploaded by

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

Day4 Conditional+Statements

The document provides an overview of Java conditional statements, including if, if..else, nested if, and switch statements, explaining their syntax and usage. It also includes lab assignments for each type of statement, prompting users to write programs that apply these concepts in various scenarios. The focus is on controlling program flow based on specific conditions.

Uploaded by

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

Day 4

Conditional Statements

Java Conditional Statements

Java conditional statements allow you to control the flow of your program by executing certain
pieces of code based on specific conditions.

1) if Statement

The if statement is the most basic form of conditional statement. It checks a condition and executes
the block of code inside it if the condition is true.

Syntax:

Example:

2) if..else Statement

The if..else statement provides an alternative block of code to execute if the condition in the if
statement is false.

Syntax:

https://www.pavanonlinetrainings.com https://www.youtube.com/@sdetpavan
Example:

3) Nested if Statement

A nested if statement is an if or if..else statement inside another if or if..else statement. It allows you
to check multiple conditions sequentially.

Syntax:

Example:

4) switch Statement

The switch statement is used to execute one block of code out of many based on the value of an
expression. It's an alternative to using multiple if..else if statements.

https://www.pavanonlinetrainings.com https://www.youtube.com/@sdetpavan
Syntax:

Example:

https://www.pavanonlinetrainings.com https://www.youtube.com/@sdetpavan
Lab Assignments
if Statement

1. Write a program that takes an integer input and checks if the number is positive.

2. Write a program that takes an age as input and checks if the person is eligible to vote.

3. Write a program that takes a year as input and checks if it is a leap year.

4. Write a program that takes a character as input and checks if it is an uppercase letter.

5. Write a program that takes an integer input and checks if the number is a multiple of 10.

if..else Statement

1. Write a program that takes an integer input and determines whether it is even or odd.

2. Write a program that takes an age as input and checks if the person is a teenager (age
between 13 and 19).

3. Write a program that takes two integers as input and prints the larger number.

4. Write a program that takes an integer input and checks if the number is positive, negative, or
zero.

5. Write a program that takes an age as input and checks if the person is eligible for a senior
citizen discount (age >= 60).

Nested if Statement

1. Write a program that takes an integer input and checks if it is both positive and even.

2. Write a program that takes a character as input and checks if it is an uppercase vowel.

3. Write a program that takes three integers as input and finds the largest number.

4. Write a program that takes an integer input and checks if it is a multiple of both 5 and 10.

5. Write a program that takes a score as input and determines the grade based on the score
(e.g., A, B, C, etc.).

6. Write a program that takes a character as input and checks if it is a vowel or consonant.

7. Write a program that takes an integer input and checks if it is divisible by both 2 and 3.

switch Statement

1. Write a program that takes an integer (1-7) as input and prints the corresponding day of the
week.

2. Write a program that takes an integer (1-12) as input and prints the corresponding month
name.

3. Write a program that takes a score as input and displays the corresponding grade using a
switch statement.

https://www.pavanonlinetrainings.com https://www.youtube.com/@sdetpavan
4. Write a program that takes two numbers and an operator (+, -, *, /) as input and performs
the corresponding arithmetic operation.

5. Write a program that takes an integer (1-12) as input and prints the corresponding season.

https://www.pavanonlinetrainings.com https://www.youtube.com/@sdetpavan

You might also like