Java.util.Scanner.skip() 方法
描述
java.util.Scanner.skip(String pattern) 方法跳过与从指定字符串构造的模式匹配的输入。调用此方法的形式为 skip(pattern) 的行为方式完全相同 作为调用skip(Pattern.compile(pattern))。
声明
以下是 java.util.Scanner.skip() 方法的声明
public Scanner skip(String pattern)
参数
pattern − 指定要跳过的模式的字符串
返回值
此方法返回此扫描仪
异常
IllegalStateException − 如果此扫描仪已关闭
示例
下面的例子展示了 java.util.Scanner.skip() 方法的使用。
package com.tutorialspoint;
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);
// skip the word "Hello"
scanner.skip("Hello");
// print a line of the scanner
System.out.println("" + scanner.nextLine());
// close the scanner
scanner.close();
}
}
让我们编译并运行上面的程序,这将产生以下结果 −
World! 3 + 3.0 = 6.0 true

