TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Java Tutorials

Java if-else statement with Examples

Overview

Java if-else is a control structure and is used to make decisions based on conditions. We can use this statement to branch out code based on branch conditions.

Java if-else statement

If the given condition is True the program executes one path, and if the condition is false the program takes another path.

Let’s see a simple example, below a sample piece of  Java code:

public class JavaIFExample 
{
 
 public static void main(String[] args)
 {
 
 int dummyVariable = 70 ;
 
 if(dummyVariable > 100)
 { 
 System.out.println("dummyVariable > 100 ");
 } 
 else 
 { 
 System.out.println("dummyVariable < 100 "); }
 
 }

}

 

Output of the Program

dummyVariable < 100

 

Control Structures

 

The program output depends on what the if condition evaluates to True or False. The program executes the code depending on the value of dummyVariable in the above program.

 

—

Java Tutorials

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/java/

Related Posts

Download Greenfoot Windows

Java Tutorials /

Download & Install Greenfoot on Windows

Java Tutorials /

Java Static Code Analysis

Java Tutorials /

Java Testing Tools

Java Tutorials /

Handle Multiple Exceptions in Java

Exceptions_In_Java

Java Tutorials /

Exceptions in Java Programs

‹ Java For Loop with Examples› Java switch statement

Recent Posts

  • Update draw.io on Windows
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com