Java If Else

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.

Syntax:

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

Flow Diagram:

Java If Else

Read also – For Loop Example

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.in);
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.");
}
else{
System.out.println("James has failed the test.");
}
}
}

Output:

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

About the author

admin

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *