luoni

DifferentIntegerSize

May 28th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. package DataTypes;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class DifferentIntegersSize {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. String input = scanner.nextLine();
  9.  
  10. try {
  11. long value = Long.parseLong(input);
  12.  
  13. System.out.println(value + " can fit in:");
  14. if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
  15. System.out.println("* byte");
  16. }
  17. if (value >= Short.MIN_VALUE && value <= Short.MIN_VALUE) {
  18. System.out.println("* short");
  19. }
  20. if (value >= -Integer.MIN_VALUE && value <= Integer.MAX_VALUE) {
  21. System.out.println("* int");
  22. }
  23. if (value >= Long.MIN_VALUE && value <= Long.MAX_VALUE) {
  24. System.out.println("* long");
  25. }
  26. } catch (Exception e) {
  27. System.out.println(input+" can't fit in any type");
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment