Java.util.Scanner.hasNextByte() 方法
描述
java.util.Scanner.hasNextByte(int radix) 如果可以使用 nextByte() 方法将此扫描器输入中的下一个标记解释为指定基数中的字节值,则该方法返回 true。 扫描仪不会超过任何输入。
声明
以下是 java.util.Scanner.hasNextByte() 方法的声明
public boolean hasNextByte(int radix)
参数
radix − 用于将 token 解释为字节值的基数
返回值
当且仅当此扫描器的下一个标记是有效的字节值时,此方法才返回 true
异常
IllegalStateException − 如果此扫描仪已关闭
示例
下面的例子展示了 java.util.Scanner.hasNextByte() 方法的使用。
package com.tutorialspoint;
import java.util.*;
public class ScannerDemo {
public static void main(String[] args) {
String s = "Hello World! 3 + 3.0 = 6";
// create a new scanner with the specified String Object
Scanner scanner = new Scanner(s);
while (scanner.hasNext()) {
// check if the scanner's next token is a byte with radix 4
System.out.println("" + scanner.hasNextByte(4));
// print what is scanned
System.out.println("" + scanner.next());
}
// close the scanner
scanner.close();
}
}
让我们编译并运行上面的程序,这将产生以下结果 −
false Hello false World! true 3 false + false 3.0 false = false 6

