Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // == (equal to), != (not equal to), > (greater than), < (less than)
- // >= (greater than or equal to), <= (less than or equal to)
- // && (AND), || (OR), ! (NOT)
- public class ComparisonsAndLogicalOperations {
- public static void main(String[] args) {
- int x = 10;
- int y = 5;
- int z = 20;
- boolean xLessThanY = x < y;
- if (x == 10) {
- System.out.println("x is equal to 10");
- }
- if (x != y) {
- System.out.println("x is not equal to y");
- }
- if (x > y) {
- System.out.println("x is greater than y");
- }
- if (x < z) {
- System.out.println("x is less than z");
- }
- if (x >= 10) {
- System.out.println("x is greater than or equal to 10");
- }
- if (x <= 10) {
- System.out.println("x is less than or equal to 10");
- }
- if (x == 10 && y == 5) {
- System.out.println("x is 10 and y is 5");
- }
- if (x > y && x == 10) {
- System.out.println("x is greater than y and x is 10");
- }
- if (xLessThanY || y == 5) {
- System.out.println("either x is less than y, or y is 5 (or both)");
- }
- if (!(xLessThanY) && y == 5) {
- System.out.println("x is not less then y and y is 5");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment