Java Data Type Exercises: Compare two given signed and unsigned numbers
Java Data Type: Exercise-12 with Solution
Write a Java program to compare two given signed and unsigned numbers.
Sample Solution:
Java Code:
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
Flowchart:
Java Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a Java program to test whether a given double/float value is a finite floating-point value or not.
Next: Write a Java program to compute the floor division and the floor modulus of the given dividend and divisor.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
Java: Tips of the Day
How to sort an ArrayList?
Collections.sort(testList); Collections.reverse(testList);
That will do what you want. Remember to import Collections though!
Ref: https://bit.ly/32urdSe
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework