Guest User

Untitled

a guest
Apr 26th, 2023
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1.  
  2. // == (equal to), != (not equal to), > (greater than), < (less than)
  3. // >= (greater than or equal to), <= (less than or equal to)
  4. // && (AND), || (OR), ! (NOT)
  5.  
  6. public class ComparisonsAndLogicalOperations {
  7. public static void main(String[] args) {
  8. int x = 10;
  9. int y = 5;
  10. int z = 20;
  11.  
  12. boolean xLessThanY = x < y;
  13. if (x == 10) {
  14. System.out.println("x is equal to 10");
  15. }
  16. if (x != y) {
  17. System.out.println("x is not equal to y");
  18. }
  19. if (x > y) {
  20. System.out.println("x is greater than y");
  21. }
  22. if (x < z) {
  23. System.out.println("x is less than z");
  24. }
  25. if (x >= 10) {
  26. System.out.println("x is greater than or equal to 10");
  27. }
  28. if (x <= 10) {
  29. System.out.println("x is less than or equal to 10");
  30. }
  31.  
  32.  
  33. if (x == 10 && y == 5) {
  34. System.out.println("x is 10 and y is 5");
  35. }
  36. if (x > y && x == 10) {
  37. System.out.println("x is greater than y and x is 10");
  38. }
  39. if (xLessThanY || y == 5) {
  40. System.out.println("either x is less than y, or y is 5 (or both)");
  41. }
  42. if (!(xLessThanY) && y == 5) {
  43. System.out.println("x is not less then y and y is 5");
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment