Q:

Write a Java program to compare two given signed and unsigned numbers

0

Write a Java program to compare two given signed and unsigned numbers

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

public class Main {
    public static void main(String[] args) {
        int in1 = Integer.MIN_VALUE;
		int in2 = Integer.MAX_VALUE;
		System.out.println("Signed integers: " + in1 + ", " + in2);
		System.out.println("-----------------------------------------");
		int compare_Signed_num = Integer.compare(in1, in2);
		System.out.println("Result of comparing signed numbers: " + compare_Signed_num);
		int compare_Unsigned_num = Integer.compareUnsigned(in1, in2);
        System.out.println("Result of comparing unsigned numbers: " + compare_Unsigned_num);
    }
}

Sample Output:

Signed integers: -2147483648, 2147483647
-----------------------------------------
Result of comparing signed numbers: -1
Result of comparing unsigned numbers: 1

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now