Skip to content

Commit 43314f5

Browse files
committed
bitwise sign comparison
1 parent fe28d02 commit 43314f5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package binary.compareSigns;
2+
3+
import utils.InputReader;
4+
5+
// x ^ y is negative if x and y have opposite signs
6+
public class IntSignsComparator {
7+
public static void main(String[] args) {
8+
System.out.print("Input a number: ");
9+
int x = InputReader.readInt();
10+
System.out.print("Input another number: ");
11+
int y = InputReader.readInt();
12+
13+
if ((x ^ y) < 0) {
14+
System.out.println("They have opposite signs");
15+
}
16+
else {
17+
System.out.println("They have the same sign");
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)