java.util.Scanner.useRadix(int radix)%uA0方法设置此scanner的默认基数为指定基数。
声明
以下是java.util.Scanner.useRadix()方法的声明
public Scanner useRadix(int radix)
参数
-
radix%uA0-- 扫描数字时使用的基数
返回值
此方法返回此scanner
异常
-
IllegalArgumentException%uA0-- 如果基数超出范围
例子
下面的示例演示java.util.Scanner.useRadix()方法的用法。
package com.yiibai import java.util.* public class ScannerDemo { public static void main(String[] args) { String s = "Hello World! 3 + 3.0 = 6.0 true " // create a new scanner with the specified String Object Scanner scanner = new Scanner(s) // print a line of the scanner System.out.println("" + scanner.nextLine()) // change the radix of the scanner scanner.useRadix(32) // display the new radix System.out.println("" + scanner.radix()) // close the scanner scanner.close() } }
让我们来编译和运行上面的程序,这将产生以下结果:
Hello World! 3 + 3.0 = 6.0 true 32