If Statement In Java Example
Chapter:
Control Statements
Last Updated:
17-06-2016 03:55:03 UTC
Program:
/* ............... START ............... */
public class JavaIfStatementExample {
public static void main(String[] args) {
int val1 = 10, val2 = 20;
if (val1 > val2)
System.out.println("val1 > val2");
if (val1 < val2)
System.out.println("val2 < val1");
}
}
/* ............... END ............... */
Output
Notes:
-
If statement executes a block of code only if the specified expression is true.
- Syntax : if (<conditional expression>) <statement action> .
Tags
If Statement, Java, Control Statements