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

Java

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/in/java/

Related Posts

Download Greenfoot Windows

Java /

Download & Install Greenfoot on Windows

Java /

Java Static Code Analysis

Java /

Java Testing Tools

Java /

Handle Multiple Exceptions in Java

Exceptions_In_Java

Java /

Exceptions in Java Programs

‹ Java For Loop with Examples› Java switch statement

Recent Posts

  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • RAPTOR Editions
  • Flowgorithm Conditional Breakpoint Statement
  • Flowgorithm Read Numbers from File Example
  • Search Text File Flowchart Example
  • Flowgorithm Turtle Graphics Symbols
  • Draw Circle using Flowgorithm Turtle
  • Draw Parallel Lines using Flowgorithm Graphics

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version