Java If Else

Sharing is healthy !!

In today’s post you will learn java if else statement. We will also look into its definition, syntax, flow diagram and example. So let’s get into it,

Java If Else:

Java if else statement provides secondary path of execution. When an if block statement evaluates to false then else block statements are executed.


if(condition) {
 // statements if condition is true
 }else {
 // statements if condition is false

Flow Diagram:

Java If Else

Read also – For Loop Example

import java.util.Scanner;

public class Java_If_Else {

public static void main(String[] args) {

int marks_Obtained;
int marks_Pass;

marks_Pass = 40;

Scanner sc = new Scanner(;
System.out.println("Enter marks obtained by James: ");
marks_Obtained = sc.nextInt();

if(marks_Obtained >= marks_Pass){
System.out.println("James has passed the test.");
System.out.println("James has failed the test.");


Enter marks obtained by James: 80
James has passed the test.

Sharing is healthy !!