如何从java中的标准输入读取长值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27018633/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 03:40:31  来源:igfitidea点击:

how to read a long value from standard input in java?

javainputlong-integer

提问by VBC

i am using util.Scannerto read input from the user. I don't understand how to read a long datatype value.

我正在使用util.Scanner读取用户的输入。我不明白如何读取长数据类型值。

Scanner scr=new Scanner(System.in);
long l=scr.nextInt();

I am unable to read 64-bit data using the above code — it just gives me an input mismatch exception.

我无法使用上述代码读取 64 位数据——它只是给了我一个输入不匹配异常。

采纳答案by Brovoker

use the nextLongmethod :

使用nextLong方法:

long l=scr.nextLong();