所以这就是我写的代码:粗体不会打印出我想要打印的内容,也就是说,如果输入的是长数据类型,那么短语“can be fit in a long”。
我尝试使用Math.pow
,但该函数不起作用,因为这是双数据类型。任何建议!
import java.util.*;
import http://java.io.*;
public class HackerRank {
public static void main(String[] args){
Scanner in = new Scanner(System Resources and Information.);
int n = in.nextInt();
for(int t = 0; t < n; t++){
try {
long a = in.nextInt();
if(a > -128 && a <= 127){
System.out.println(a + " can be fitted in:\n*byte");
System.out.println("*short");
System.out.println("*int");
System.out.println("*long");
} else if(a > -32768 && a <= 32767) {
System.out.println(a + " can be fitted in:\n*short");
System.out.println("*int");
System.out.println("*long");
} else if(a > Math.pow(-2, 31) && a < Math.pow(2, 31)) {
System.out.println(a + " can be fitted in:\n*int");
System.out.println("*long");
} else {
if (a >= -Math.pow(2, 63) && a < Math.pow(2, 63)-1);
System.out.println(a + " can be fitted in:\n*long");
}
} catch (Exception e){
System.out.println(in.next() + " can't be fitted anywhere.");
}
}
}
}