Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DataTypes;
- import java.util.Scanner;
- public class DifferentIntegersSize {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- try {
- long value = Long.parseLong(input);
- System.out.println(value + " can fit in:");
- if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
- System.out.println("* byte");
- }
- if (value >= Short.MIN_VALUE && value <= Short.MIN_VALUE) {
- System.out.println("* short");
- }
- if (value >= -Integer.MIN_VALUE && value <= Integer.MAX_VALUE) {
- System.out.println("* int");
- }
- if (value >= Long.MIN_VALUE && value <= Long.MAX_VALUE) {
- System.out.println("* long");
- }
- } catch (Exception e) {
- System.out.println(input+" can't fit in any type");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment