入力が多いため、最後の入力の出力は表示されません。 15個以上の異なる入力を入力すると、出力は与えられた出力数よりも1つ少なくなります。表示されていない出力が最後の出力です。cmdでプロンプトを使って適切な出力が得られません。プロンプト
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