Java Program to Perform Relational Operations

«
»
This is a Java Program to Illustrate Use of Relational Operators. The relational operators determine the relationship that one operand has to the other.

Enter any two integers as input. After that we use various relational operators on these given integers and hence get the outputs accordingly.

Here is the source code of the Java Program to Illustrate Use of Relational Operators. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

  1. import java.util.Scanner;
  2. public class Relational_Operators 
  3. {
  4.     public static void main(String args[]) 
  5.     {
  6.         Scanner s= new Scanner(System.in);
  7.         System.out.print("Enter first integer:");
  8.         int a = s.nextInt();
  9.         System.out.print("Enter second integer:");
  10.         int b = s.nextInt();
  11.         System.out.println("a == b : " + (a == b) );
  12.         System.out.println("a != b : " + (a != b) );
  13.         System.out.println("a > b : " + (a > b) );
  14.         System.out.println("a < b : " + (a < b) );
  15.         System.out.println("b >= a : " + (b >= a) );
  16.         System.out.println("b <= a : " + (b <= a) );
  17.     }
  18. }

Output:

$ javac Relational_Operators.java
$ java  Relational_Operators
 
Enter first integer:25
Enter second integer:30
a == b : false
a != b : true
a > b : false
a < b : true
b >= a : true
b <= a : false

Sanfoundry Global Education & Learning Series – 1000 Java Programs.

Note: Join free Sanfoundry classes at Telegram or Youtube
advertisement
advertisement

Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.