Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Java Nested If Statement

The document explains the concept of nested if statements in Java, providing syntax and an example demonstrating their use. It includes a sample program that checks if a number is greater than 10 and 15, along with exercises for the reader to practice checking if a number is even or odd and if three numbers are equal. The examples illustrate how to implement nested if statements effectively in Java programming.

Uploaded by

siwesapepa02
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)
14 views2 pages

Java Nested If Statement

The document explains the concept of nested if statements in Java, providing syntax and an example demonstrating their use. It includes a sample program that checks if a number is greater than 10 and 15, along with exercises for the reader to practice checking if a number is even or odd and if three numbers are equal. The examples illustrate how to implement nested if statements effectively in Java programming.

Uploaded by

siwesapepa02
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/ 2

Java Nested If Statement

We can put if statement inside another if to create nested if. Below is the syntax to declare nested if
statement.

if(conditional expressional){

statement;

if(conditional expressional){

statement

Or

if (condition1) {

// code to be executed if condition1 is true

if (condition2) {

// code to be executed if condition2 is true

Java Nested If Example

public class Demo {

public static void main(String[] args) {

int a = 20;

if (a>10) {

if (a>15) {

System.out.println("value is greater than 10 and 15");

else {

System.out.println("value is less than 10");

}
}

Output:

value is greater than 10 and 15

Exercise 1

Write a java program that allows the user to enter aa number the checks if a number is even, we also
need to check whether the number is divisible by 6. And if the number is odd, we need to check
whether the number is divisible by 3. Use nested if-else statements.

Exercise 2

Check if three numbers are equal or not using nested if statement

Input a=5

b=7

c=5

You might also like