对于大量输入输出的最后一个输入没有显示出来。 当我用来输入15个或更多的不同的输入我得到的输出是一个比给定的输出数少。不显示的输出是最后一个输出。我没有在java中使用cmd得到正确的输出.prompt
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
while(sc.hasNext())
{
try
{
long x=sc.nextLong();
System.out.println(x+" can be fitted in:");
if(x>=-128 && x<=127)System.out.println("* byte");
if(x>=-pow(2,15) && x<pow(2,15))System.out.println("* short");
if(x>=-(long)pow(2,31) && x<(long)pow(2,31))System.out.println("* int");
if(x>=-(long)pow(2,63) && x<(long)pow(2,63))System.out.println("* long");
//Complete the code
}
catch(Exception e)
{
System.out.println(sc.next()+" can't be fitted anywhere.");
}
}
请提供完整的代码。无需修改即可运行,使其更容易帮助。 – Aelexe
你基本上是通过获取nextInt()来跳过第一个输入,然后在try块的第一行获得下一个long。 – scrappedcola