You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.;
public class Solution {
public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner scan = new Scanner(System.in); int t = scan.nextInt(); boolean typeFit[] = {false,false,false,false}; boolean fit = false; String types[] = {"* byte","* short","* int","* long"}; scan.nextLine(); for (int i=0; i<t; i++) { String sample = scan.nextLine(); long sampleLong = 0l; try { System.out.print(sample); sampleLong = Long.parseLong(sample); if(sampleLong >=-128 && sampleLong <= 127) { typeFit[0]=true; fit=true; } if(sampleLong >=-32768 && sampleLong<= 32767) { typeFit[1]=true; fit=true; } if(sampleLong >=Math.pow(-2,31) && sampleLong<= Math.pow(2,31)-1) { typeFit[2]=true; fit=true; } if(sampleLong >=Math.pow(-2,63) && sampleLong<= Math.pow(2,63)-1) { typeFit[3]=true; fit=true; } } catch(Exception e) { System.out.println(" can't be fitted anywhere."); } if(fit) System.out.println(" can be fitted in:"); for(int c =0; c<4;c++) { if(typeFit[c]) { System.out.println(types[c]); typeFit[c]=false; } } fit=false; } }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Java Datatypes
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.;
public class Solution {
}