You are on page 1of 1

 Jobs   Qries  Whiteboard   Net Meeting Tools   Articles

 HOME LIBRARY  VIDEOS  Q/A  TUTOR CONNECT  CODING GROUND  Search

if-else statement in java Tutorials Point (India) Pvt. Ltd.

YouTube 39K

Advertisements

 Previous Page Next Page 

An if statement can be followed by an optional else statement, which


executes when the Boolean expression is false.

Syntax
Java Tutorial Following is the syntax of an if...else statement −

Java - Home if(Boolean_expression) {


// Executes when the Boolean expression is true
Java - Overview
}else {
Java - Environment Setup // Executes when the Boolean expression is false
}
Java - Basic Syntax
If the boolean expression evaluates to true, then the if block of code will be
Java - Object & Classes
executed, otherwise else block of code will be executed.
Java - Basic Datatypes

Java - Variable Types


Flow Diagram
Java - Modi er Types

Java - Basic Operators

Java - Loop Control

Java - Decision Making

Java - Numbers

Java - Characters

Java - Strings

Java - Arrays

Java - Date & Time

Java - Regular Expressions

Java - Methods Example


Java - Files and I/O  Live Demo
public class Test {
Java - Exceptions
public static void main(String args[]) {
Java - Inner classes int x = 30;

if( x < 20 ) {
System.out.print("This is if statement");
Java Object Oriented }else {
System.out.print("This is else statement");
Java - Inheritance }
}
Java - Overriding }

Java - Polymorphism This will produce the following result −

Java - Abstraction
Output
Java - Encapsulation
This is else statement
Java - Interfaces

Java - Packages The if...else if...else Statement


An if statement can be followed by an optional else if...else statement, which
Java Advanced is very useful to test various conditions using single if...else if statement.

Java - Data Structures When using if, else if, else statements there are a few points to keep in mind.

Java - Collections An if can have zero or one else's and it must come after any else if's.
Java - Generics An if can have zero to many else if's and they must come before the
Java - Serialization else.

Java - Networking Once an else if succeeds, none of the remaining else if's or else's will
be tested.
Java - Sending Email

Java - Multithreading Syntax


Java - Applet Basics Following is the syntax of an if...else statement −
Java - Documentation
if(Boolean_expression 1) {
// Executes when the Boolean expression 1 is true

Java Useful Resources }else if(Boolean_expression 2) {


// Executes when the Boolean expression 2 is true
Java - Questions and Answers }else if(Boolean_expression 3) {
// Executes when the Boolean expression 3 is true
Java - Quick Guide
}else {
Java - Useful Resources // Executes when the none of the above condition is true.
}
Java - Discussion

Java - Examples Example


Selected Reading  Live Demo
public class Test {

Developer's Best Practices public static void main(String args[]) {


int x = 30;
Questions and Answers
if( x == 10 ) {
E ective Resume Writing System.out.print("Value of X is 10");
}else if( x == 20 ) {
HR Interview Questions System.out.print("Value of X is 20");
}else if( x == 30 ) {
Computer Glossary System.out.print("Value of X is 30");
}else {
System.out.print("This is else statement");
Who is Who
}
}
}

This will produce the following result −

Output
Value of X is 30

 Previous Page  Print Next Page 

Advertisements
Ad

Build react apps twice as fast with Kendo UI for


React. Try now

Progress Telerik DOWNLOAD

Write for us FAQ's Helping Contact © Copyright 2018. All Rights Reserved. Enter email for newsletter go

You might also like