-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRelationalOperators.java
More file actions
53 lines (40 loc) · 1.4 KB
/
RelationalOperators.java
File metadata and controls
53 lines (40 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.nishith.java.operators;
public class RelationalOperators {
public static void main(String[] args) {
int number = 7;
// Always return true or false
// <, <=, >, >=, ==, and !=
// greater than operator
System.out.println(number > 5);// true
System.out.println(number > 7);// false
// greater than equal to operator
System.out.println(number >= 7);// true
// less than operator
System.out.println(number < 9);// true
System.out.println(number < 7);// false
// less than equal to operator
System.out.println(number <= 7);// true
// is equal to operator
System.out.println(number == 7);// true
System.out.println(number == 9);// false
// NOT equal to operator
System.out.println(number != 9);// true
System.out.println(number != 7);// false
// NOTE : single = is assignment operator
// == is comparison. Below statement uses =.
System.out.println(number = 7);// 7
// Equality for Primitives only compares values
int a = 5;
int b = 5;
// compares if they have same value
System.out.println(a == b);// true
// Equality for Reference Variables.
Integer aReference = new Integer(5);
Integer bReference = new Integer(5);
// compares if they are refering to the same object
System.out.println(aReference == bReference);// false
bReference = aReference;
// Now both are referring to same object
System.out.println(aReference == bReference);// true
}
}