当我在java中运行以下代码时:
import java.util.*;
class Solution{
public static void main(String []argh)
{
Scanner sc = new Scanner(System.in);
try{
long x=sc.nextLong();
System.out.println(x);
}
catch(Exception e){
System.out.println(sc.next()+" can't be fitted anywhere.");
}
sc.close();
}
}
并将输入输入为“23333333333333333333333333333333333333333”,它给出以下输出:
23333333333333333333333333333333333333333 can't be fitted anywhere.
当sc.nextLong()
抛出时,catch 块中的InputMismatchException
如何获得与try 块中sc.next()
输入的完全相同的值?sc.nextLong()
它不应该在这里要求控制台输入代码的输入吗?