Of course it's nested. Nesting has nothing to do with the way you format the code.

if (...)
{
    // some code
}
else if (...)
{
    // some code
}
else
{
    // some code
}

is exactly equivalent to

if (...)
{
    // some code
}
else
{
    if (...)
    {
        // some code
    }
    else
    {
        // some code
    }
}

There's no 'else if' keyword in Java, the effect is achieved purely by a formatting convention which stops long chains of nested elses from drifting right across the screen.

In case anybody needs persuading, here is the specification for an if statement: Java Language Specification section 14.9

Answer from JeremyP on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_conditions_nested.asp
Java Nested If Statements
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... You can also place an if statement inside another if. This is called a nested if statement.
๐ŸŒ
Codedamn
codedamn.com โ€บ news โ€บ java
Nested if-else statement in Java (with examples)
October 18, 2022 - In the above example, if the if-condition is satisfied, the statement inside it is executed otherwise it moves to the else part. The number a=10 is divisible by 5, so it prints โ€œDivisible by 5โ€ and the else statement is skipped.
People also ask

When should I use nested if statements instead of switch statements in Java?
Use nested if statements instead of switch statements when you need to evaluate conditions that don't involve a single variable or require relational or logical operators, as switch supports only simpler cases with singular values or expressions derived from those values.
๐ŸŒ
vaia.com
vaia.com โ€บ java nested if
Java Nested If: Statements, Syntax & Examples | Vaia
What is the difference between nested if and else if in Java?
Nested if involves placing an if statement inside another if statement, allowing for multiple levels of condition checks. In contrast, else if is part of the if-else ladder, used for checking multiple conditions in sequence but on the same level, executing only the first true condition.
๐ŸŒ
vaia.com
vaia.com โ€บ java nested if
Java Nested If: Statements, Syntax & Examples | Vaia
How can nested if statements affect the readability of Java code?
Nested if statements can significantly affect code readability by making it harder to follow the logic, especially as the nesting levels increase. Deeply nested structures can lead to "spaghetti code," which is difficult to maintain and debug. Simplifying logic with methods or using switch/case can improve readability.
๐ŸŒ
vaia.com
vaia.com โ€บ java nested if
Java Nested If: Statements, Syntax & Examples | Vaia
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ nested-if-in-java
Java Nested if - GeeksforGeeks
July 23, 2025 - // Java Program to demonstrate ... Geeks { public static void main(String args[]) { int a = 10; int b = 20; // Outer if condition if (a == 10) { // Inner if condition if (b != 20) { System.out.println("GeeksforGeeks"); } else { System.out.println("GFG"); } } } } ... Explanation: In the above example, it first checks if a is equal to 10....
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ nested_if_statements_in_java.htm
Java - nested if statement
In this example, we're showing use of nested if statement within an else statement. We've initialized two variables x and y to 30 and 20 respectively. Then we're checking value of x less than 30 using if statement.
๐ŸŒ
Coders Campus
coderscampus.com โ€บ home โ€บ nested if statements
Nested IF statements - Coders Campus
April 27, 2021 - So, as predictable as the sun will rise and set, Java will follow the same set of rules for this new if..else block. We will now evaluate if age is less than 65. And as luck would have it, our variable is set to 29. So, yes, 29 is less than 65, so we'll execute the code inside of this block and the console will output โ€œYou are an adult.โ€ ยท You have to consider the fact that you are now inside of nested if statements and make note of where the beginning and end of all of those curly braces {} are.
๐ŸŒ
Scientech Easy
scientecheasy.com โ€บ home โ€บ blog โ€บ if else in java | nested if else, example
If Else in Java | Nested If Else, Example - Scientech Easy
February 12, 2026 - In the above example, if x is greater than y and y is greater than z, statement1 will execute. If x is greater than y but y is not greater than z then statement1 will not execute. In this case, else part (statement2) will execute. Letโ€™s take an example program based on Java nested if statements.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ decision-making-javaif-else-switch-break-continue-jump
Decision Making in Java - Conditional Statements - GeeksforGeeks
The below diagram demonstrates the flow chart of an "nested-if Statement execution flow" in programming. ... The if-else-if ladder allows multiple independent conditions to be checked in order. As soon as one condition is true, its block executes, and the rest are skipped. ... import java.util.*; class Geeks { public static void main(String args[]) { int i = 20; if (i == 10) System.out.println("i is 10"); else if (i == 15) System.out.println("i is 15"); else if (i == 20) System.out.println("i is 20"); else System.out.println("i is not present"); } }
Published ย  October 6, 2025
๐ŸŒ
Vaia
vaia.com โ€บ java nested if
Java Nested If: Statements, Syntax & Examples | Vaia
Nested If Statements Java: Involves placing an 'if' statement inside another 'if' statement to check sequential conditions. Nested If Syntax in Java: Uses 'if' blocks inside other 'if' or 'if-else' blocks to handle compound logical scenarios.
๐ŸŒ
DEV Community
dev.to โ€บ paulike โ€บ nested-if-and-multi-way-if-else-statements-3neh
Nested if and Multi-Way if-else Statements - DEV Community
May 2, 2024 - if (i > k) { if (j > k) System.out.println("i and j are greater than k"); } else System.out.println("i is less than or equal to k"); The if (j > k) statement is nested inside the if (i > k) statement.
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ if-else-statement
Java if...else (With Examples)
Statement outside if...else block ยท Here, the value of number is -5. So the test expression evaluates to false. Hence code inside the body of else is executed. In Java, we have an if...else...if ladder, that can be used to execute one block of code among multiple other blocks.
๐ŸŒ
PREP INSTA
prepinsta.com โ€บ home โ€บ java tutorial โ€บ java conditional statement: nested if-else statements
Nested if-else - Java Conditional Statement
December 8, 2022 - Now that we have seen the syntax of the nested if- else statement, let us understand it further with the help of an example. ... public class Main { public static void main(String[] args) { int a= 100; if(a<250) { if(a<150) System.out.println("Hey Prepster, Happy Learning"); else System.out.println("Keep going, keep learning"); } else System.out.println("Welcome to Prepinsta"); } } ... Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
๐ŸŒ
Vaia
vaia.com โ€บ java if else statements
Java If Else Statements: Syntax & Examples | Vaia
Java Nested If Else Statements: Placing if else statements within another block to manage multi-level checks and complex logic. Java If Else Statement Examples: Different examples illustrate the practical application of conditional logic in Java.
๐ŸŒ
Tutorial Gateway
tutorialgateway.org โ€บ nested-if-in-java-programming
Nested If in Java Programming
March 26, 2025 - OUTPUT 1: From the nested if statement screenshot below, you can observe that We entered the age of 16. Here, the first If condition is TRUE. So, the statements inside the first if block will execute. We will enter the age as 25 means the first IF expression is FALSE. It will go to the else block. Within the else block, Javac will check the if (age>= 18 && age<=60), which is TRUE.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ what is nested if statement in java?
What is Nested if Statement in Java? - Scaler Topics
September 16, 2022 - Now we will see an example where the nested if conditions are implemented only using the if condition. In this example, we are given two numbers, x and y. These nummbers are to be checked if they are equal with 30 and 40 respectively based on ...
๐ŸŒ
Refreshjava
refreshjava.com โ€บ java โ€บ else-if-and-nested-if-else
Java if...else if condition - Java nested if else - RefreshJava
Yes, this is also known as nested if else in java. Refer the example above. ... Ensure there is space between else & if, it should not be elseif. The else if is also part of conditional or decision making statements.
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ java tutorial โ€บ nested if statements in java
Nested if Statements in Java | Guide to Nested if Statements in Java
March 27, 2023 - In this case, as the first condition itself is not satisfied, the else part gets executed. That is, a line will be printed asโ€ The number 20 is less than 23โ€. Nested if Statement is a decision-making statement in Java containing certain branches with an if condition inside another if condition. Syntax, working, and examples of Nested-if is discussed in this document.
Call ย  +917738666252
Address ย  Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
Codevisionz
codevisionz.com โ€บ home โ€บ java code example: nested if-else statement
Java Code Example: nested if-else statement
May 31, 2023 - If number is greater than 100, the code block inside the else statement is executed, which prints a message indicating that number is greater than 100. In this case, number is between 51 and 100, so the code block inside the second else statement is executed, and the output will be โ€œValue ...
๐ŸŒ
Testmuai
testmuai.com โ€บ software-testing-questions โ€บ java-if-else-if
Write a Java program to demonstrate nested if โ€ฆ else if .. statement?
... if(condition1){ //execute the code if condition1 is true }else if(condition2){ //execute the code if condition2 is true } else if(condition3){ //execute the code if condition3 is true } ... else{ //execute the code if all the conditions ...
๐ŸŒ
Studytonight
studytonight.com โ€บ java-programs โ€บ java-nested-if-program
Java Nested If Program - Studytonight
April 1, 2021 - In this program, we will see the implementation of the nested if-else statements in a java program. ... Create an instance of the Scanner class. Declare a variable to store the department name. Ask the user to initialize the year. Use the first if statement to check the department of the student. Use the inner if statement to check in which year the student is. Display the result. ... Below is the Java code example for nested if-else.