Compare two unsigned numbers in Java



 Write a program that compares the given two numbers as unsigned.

Java program that compares the given two numbers as unsigned

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

Output:

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

Free Spring Boot Tutorial - 5 Hours Full Course


Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course

Comments