HR자바 Java Datatypes

개요[ | ]

HR자바 Java Datatypes
해커랭크 Java
# 문제 비고
HR자바 Introduction e
1 HR자바 Welcome to Java!
2 HR자바 Java Stdin and Stdout I
3 HR자바 Java If-Else
4 HR자바 Java Stdin and Stdout II
5 HR자바 Java Output Formatting
6 HR자바 Java Loops I
7 HR자바 Java Loops II
8 HR자바 Java Datatypes
9 HR자바 Java End-of-file
10 HR자바 Java Static Initializer Block
11 HR자바 Java Int to String
12 HR자바 Java Date and Time
13 HR자바 Java Currency Formatter

import java.util.*;
import java.io.*;

class Solution{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t=sc.nextInt();
        for(int i=0;i<t;i++) {
            try {
                long x=sc.nextLong();
                System.out.println(x+" can be fitted in:");
                if( x>=-128 && x<=127 ) System.out.println("* byte");
                if( x>=-32768 && x<=32767 ) System.out.println("* short");
                if( x>=-Math.pow(2,31) && x<=Math.pow(2,31)-1 ) System.out.println("* int");
                if( x>=-Math.pow(2,63) && x<=Math.pow(2,63)-1 ) System.out.println("* long");
            }
            catch(Exception e) {
                System.out.println(sc.next()+" can't be fitted anywhere.");
            }
        }
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}