Les opérateurs relationnels

SymboleExempleCas où le résultat renvoit True
>opérande1 > opérande2opérande1 est strictement supérieur à opérande2
>=opérande1 >= opérande2opérande1 est supérieur ou égal à  opérande2
<opérande1 < opérande2opérande1 est strictement inférieur à opérande2
<=opérande1 <= opérande2opérande1 est inférieur ou égal à opérande2
==opérande1 == opérande2opérande1 est égal à opérande2
!=opérande1 != opérande2opérande1 n'est pas égal à opérande2

Exemple

  1. public class OperateursRelationnels {
  2. public static void main(String[] args) {
  3.  
  4. //a few numbers
  5. int i = 37;
  6. int j = 42;
  7. int k = 42;
  8. System.out.println("Variable values...");
  9. System.out.println(" i = " + i);
  10. System.out.println(" j = " + j);
  11. System.out.println(" k = " + k);
  12.  
  13. //greater than
  14. System.out.println("Greater than...");
  15. System.out.println(" i > j = " + (i > j)); //false
  16. System.out.println(" j > i = " + (j > i)); //true
  17. System.out.println(" k > j = " + (k > j)); //false, they are equal
  18.  
  19. //greater than or equal to
  20. System.out.println("Greater than or equal to...");
  21. System.out.println(" i >= j = " + (i >= j)); //false
  22. System.out.println(" j >= i = " + (j >= i)); //true
  23. System.out.println(" k >= j = " + (k >= j)); //true
  24.  
  25. //less than
  26. System.out.println("Less than...");
  27. System.out.println(" i < j = " + (i < j)); //true
  28. System.out.println(" j < i = " + (j < i)); //false
  29. System.out.println(" k < j = " + (k < j)); //false
  30.  
  31. //less than or equal to
  32. System.out.println("Less than or equal to...");
  33. System.out.println(" i <= j = " + (i <= j)); //true
  34. System.out.println(" j <= i = " + (j <= i)); //false
  35. System.out.println(" k <= j = " + (k <= j)); //true
  36.  
  37. //equal to
  38. System.out.println("Equal to...");
  39. System.out.println(" i == j = " + (i == j)); //false
  40. System.out.println(" k == j = " + (k == j)); //true
  41.  
  42. //not equal to
  43. System.out.println("Not equal to...");
  44. System.out.println(" i != j = " + (i != j)); //true
  45. System.out.println(" k != j = " + (k != j)); //false
  46.  
  47. }
  48. }

Ce qui donne en sortie :

Variable values...
 i = 37
 j = 42
 k = 42
Greater than...
 i > j = false
 j > i = true
 k > j = false
Greater than or equal to...
 i >= j = false
 j >= i = true
 k >= j = true
Less than...
 i < j = true
 j < i = false
 k < j = false
Less than or equal to...
 i <= j = true
 j <= i = false
 k <= j = true
Equal to...
 i == j = false
 k == j = true
Not equal to...
 i != j = true
 k != j = false

Contents Haut

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 24/04/2005, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/programmation-operateur-relationnel.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.