java scanner_Java Scanner skip()方法与示例

java scanner

扫描仪类skip()方法 (Scanner Class skip() method)

Syntax:

句法:

    public Scanner skip(Pattern patt);
public Scanner skip(String patt);

  • skip() method is available in java.util package.

    skip()方法在java.util包中可用。

  • skip(Pattern patt) method is used to skip input that meets the given pattern, avoiding delimiters.

    skip(Pattern patt)方法用于跳过符合给定模式的输入,避免使用分隔符。

  • skip(String patt) method is used to skip input that meets the pattern formed from the given string (patt).

    skip(String patt)方法用于跳过符合由给定字符串(patt)形成的模式的输入。

  • These methods may throw an exception at the time of skipping input that meets the given pattern.

    这些方法在跳过符合给定模式的输入时可能会引发异常。

    • NoSuchElementException: This exception may throw when the given pattern does not exist.NoSuchElementException :如果给定模式不存在,则可能引发此异常。
    • IllegalStateException: This exception may throw when this Scanner is not opened.IllegalStateException :如果未打开此扫描器,则可能引发此异常。
  • These are non-static methods and it is accessible with the class object only and if we try to access these methods with the class name then we will get an error.

    这些是非静态方法,只能通过类对象访问,如果尝试使用类名称访问这些方法,则会收到错误消息。

Parameter(s):

参数:

  • In the first case, skip(Pattern patt),

    在第一种情况下,请跳过(Pattern patt)

    • Pattern patt – represents the pattern to skip.
    • 模式patt –表示要跳过的模式。
  • In the second case, skip(String patt),

    在第二种情况下, skip(String patt)

    • String patt – represents a string denoting the pattern to skip.
    • 字符串模式–表示表示要跳过的模式的字符串。

Return value:

返回值:

In both the cases, the return type of the method is Scanner, it retrieves this Scanner object.

在这两种情况下,方法的返回类型均为Scanner ,它将检索此Scanner对象。

Example 1:

范例1:

// Java program to demonstrate the example 
// of skip() method of Scanner
import java.util.*;
import java.util.regex.*;
public class Skip {
public static void main(String[] args) {
String str = "Java Programming! 3 * 8= 24";
// Instantiates Scanner
Scanner sc = new Scanner(str);
// By using skip(Pattern) method
// is to skip that meets the given
// pattern
sc.skip(Pattern.compile(".ava"));
System.out.println("sc.skip(): " + sc.nextLine());
// Scanner closed
sc.close();
}
}

Output

输出量

sc.skip():  Programming! 3 * 8= 24

Example 2:

范例2:

import java.util.*;
import java.util.regex.*;
public class Skip {
public static void main(String[] args) {
String str = "Java Programming! 3 * 8= 24";
// Instantiates Scanner
Scanner sc = new Scanner(str);
// By using skip(String) method
// is to skip that meets the given
// pattern constructed from the given
// String
sc.skip("Java");
System.out.println("sc.skip(Java): " + sc.nextLine());
// Scanner closed
sc.close();
}
}

Output

输出量

sc.skip(Java):  Programming! 3 * 8= 24

翻译自: https://www.includehelp.com/java/scanner-skip-method-with-example.aspx

java scanner

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541002.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

MySQL文件后_MySQL误删除文件后,如何恢复

MySQL在运行中,如果误删除数据文件,只有服务进程没有退出,那么就有办法将其恢复。首先介绍Linux下lsof:他可以显示打开的文件和网络连接。其次/proc目录包含了反映内核和进程树的各种文件。/proc/504目录包含的是PID是504的进程信…

【载誉】致远互联荣获“2017最佳协同管理解决方案”殊荣

6月15日,一年一度的大连软交会于大连市世界博览广场盛大举行。“2017企业服务创新论坛”作为软交会最重要的组成部分之一,本年度以“守正出新——通往基业长青的数字化选择”为主题,吸引到近200位企业级服务领域的企业家及高管参加。致远互联…

c++ cdi+示例_C ++中带有示例的本地类

c cdi示例C 中的本地类 (Local Class in C) In C, generally a class is declared outside of the main() function, which is global for the program and all functions can access that class i.e. the scope of such class is global. 在C 中,通常在main()函数外…

RabbitMQ安装|使用|概念|Golang开发

手册:http://www.rabbitmq.com/getstarted.html 安装:http://www.rabbitmq.com/download.html 参考:http://blog.csdn.net/whycold/article/details/41119807 一.介绍 AMQP,即Advanced Message Queuing Protocol,高级消息队列协议&#xff0c…

python中的替换函数_python:替换模块类中的函数

我试图替换类中定义的函数,以便在不更改实际代码的情况下修改其函数(如内部工作)。我以前从来没有这样做过,因此在更换它时遇到一些问题。更改代码会让我访问python库中的包,这不是一个很好的选择。例如,如果模块名为testmodclass testMOD(object):def testFunc(self, variable…

诺基亚AirScale支持低频段和高频段5G服务 确保运营商投资收入

据悉,诺基亚创新和测试强调了其AirScale无线产品组合的灵活性、可升级性和可扩展性,以适应技术初始应用中实现的5G频段。 通过证明AirScale能够支持低频和高频,运营商将能够从5G推出的第一天提供广泛的覆盖和室内覆盖,而无需进行复…

MS的完整形式是什么?

硕士:理学硕士/外科硕士/ MicroSoft (MS: Master of Science / Master of Surgery / MicroSoft) 1)硕士:理学硕士 (1) MS: Master of Science) MS is an abbreviation of Master of Science. It is a masters degree program provided by universities i…

java 线程安全的linkedlist_使ArrayList,LinkedList变成线程安全的

1.使用SynchronizedListSynchronizedList是一个线程安全的包装类。继承于SynchronizedCollection,SynchronizedCollection实现了Collection接口,SynchronizedList包含一个List对象,对List的访问修改方法进行了一些封装,在封装的方…

人工智能能够构建一个自主驱动云吗?

企业和组织可以从云计算中受益,但许多公司并不希望面对公共云的成本,性能和治理问题,并且认为构建自己的私有云的复杂性和运营开销并没有那么困难。 如今,一些云计算供应商正在使用人工智能(AI)来简化私有云…

scala中def_def关键字以及Scala中的示例

scala中defScala def关键字 (Scala def keyword) The def keyword in Scala is used to declare functions and methods in Scala. Scala being ignorant on the data types does the same with the return type of a function. Declaring and defining a function in Scala do…

前端必备的 web 安全知识手记

前言 安全这种东西就是不发生则已,一发生则惊人。作为前端,平时对这方面的知识没啥研究,最近了解了下,特此沉淀。文章内容包括以下几个典型的 web 安全知识点:XSS、CSRF、点击劫持、SQL 注入和上传问题等(…

php脚本开头注释_PHP文件注释标记及规范小结

PHP文件注释标记及规范小结发布时间:2016-06-17 来源: 点击:次PHP 注释标记access使用范围:class,function,var,define,module该标记用于指明关键字的存取权限:private、public或protecedauthor指明作者copyright使用范围&#xf…

Salesforce宣布5.82亿美元收购文件编辑公司Quip

北京时间8月2日消息,据路透社报道,云软件开发商Salesforce.com周一宣布,已同意以大约5.82亿美元收购文件编辑创业公司Quip。 Salesforce此前已经对Quip进行了投资。Quip开发的文字处理平台供企业员工用于在移动设备、可穿戴设备以及台式机上编…

Java中的main()方法是强制性的吗?

The question is that "Is main() method is compulsory in Java?" 问题是“ main()方法在Java中是强制性的吗?” Yes, we can write a java program without main() method but there is a condition if and only if java JDK version till JDK 5. 是的…

php date( w ),PHP Date()函数详解

页面的最上方加上:date_default_timezone_set(PRC); /*把时间调到北京时间,php5默认为格林威治标准时间*/date ()a: "am"或是"pm"A: "AM"或是"PM"d: 几日,两位数字,若不足则补零&#xff1b…

10.6-全栈Java笔记:常见流详解(四)

上节我们讲到「Java中常用流:数据流和对象流」,本节我们学习文件字符流和文件缓冲流~文件字符流前面介绍的文件字节流可以处理所有的文件,但是字节流不能很好的处理Unicode字符,经常会出现“乱码”现象。所以,我们处理…

python 示例_带有示例的Python File open()方法

python 示例文件open()方法 (File open() Method) open() method is an inbuilt method in Python, it is used to create, open or append a file. open()方法是Python中的内置方法,用于创建,打开或附加文件。 Syntax: 句法: file_object …

php属于脚本,php是脚本语言吗

PHP即“超文本预处理器”,是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。PHP独特的语法混合了C、Java、Perl以及 PHP 自创的语法。利于学习,使用广泛,主要适用于Web开发领…

NetMarketShare:本月桌面浏览器市场份额几乎没有变化

NetMarketShare之前关于台式机浏览器市场份额的报告表示,Google Chrome市场份额正在快速上升,而Edge浏览器市场份额正在以蜗牛的速度前进。而该公司的最新统计数据显示,几乎所有浏览器的市场份额或多或少保持不变。 NetMarketShare的最新统计…

treeset java_Java TreeSet add()方法与示例

treeset javaTreeSet类的add()方法 (TreeSet Class add() method) add() method is available in java.util package. add()方法在java.util包中可用。 add() method is used to add the given object(ob) to this TreeSet when it does not already exist otherwise it ignore…