Saturday, April 22, 2017

Java - Example for Relational Operators

Copy and paste the following Java program in Test.java file and compile and run this program.

Example

public class Test {

public static void main(String args[]) {
int a = 10;
int b = 20;

System.out.println("a == b = " + (a == b) );
System.out.println("a != b = " + (a != b) );
System.out.println("a > b = " + (a > b) );
System.out.println("a < b = " + (a < b) );
System.out.println("b >= a = " + (b >= a) );
System.out.println("b <= a = " + (b <= a) );
}
}
This will produce the following result −

Output

a == b = false
a != b = true
a > b = false
a < b = true
b >= a = true
b <= a = false

No comments:

Post a Comment

150+java interview questions and answers

Java Platform 1 . Why is Java so popular? 2 . What is platform independence? 3 . What is bytecode? 4 . Compare JDK vs JVM vs JRE 5 ....