public static void main(String argv[]){
String a="0700";
Scanner s = new Scanner(a);
while(s.hasNextLong()){
System.out.print(s.nextLong()+",");
}
Run Code Online (Sandbox Code Playgroud)
结果将是"700",而不是"448".
默认情况下,扫描程序假定该数字位于基数10并且将忽略前导0.如果需要,您可以指定另一个基数 - 下面的代码打印448:
public static void main(String[] args) {
String a = "0700";
Scanner s = new Scanner(a);
while (s.hasNextLong(8)) { //make sure the number can be parsed as an octal
System.out.print(s.nextLong(8)); //read as an octal value
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
151 次 |
| 最近记录: |