java 方法 示例

扫描器类的hasNextShort()方法 (Scanner Class hasNextShort() method)

Syntax:

句法:

    public boolean hasNextShort();
public boolean hasNextShort(int rad);

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

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

  • hasNextShort() method is used to check whether this Scanner has next token in its input can be manipulated as a short value in the implicit radix or not.

    hasNextShort()方法用于检查此扫描程序在其输入中是否具有下一个标记,可以将其作为隐式基数中的short值进行操作。

  • hasNextShort(int rad) method is used to check whether this Scanner has next token in its input can be manipulated as a short value in the explicit radix(rad) or not.

    hasNextShort(int rad)方法用于检查此扫描程序在其输入中是否具有下一个标记是否可以作为显式基数(rad)中的short值进行操作。

  • These methods may throw an exception at the time of representing input as a short value.

    在将输入表示为短值时,这些方法可能会引发异常。

    IllegalStateException: This exception may throw when this Scanner is not opened.

    IllegalStateException :如果未打开此扫描器,则可能引发此异常。

  • These are non-static methods, it is accessible with class object & if we try to access these methods with the class name then we will get an error.

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

Parameter(s):

参数:

  • In the first case, hasNextShort(),

    在第一种情况下, hasNextShort()

    • It does not accept any parameter.
  • In the second case, hasNextShort(int rad),

    在第二种情况下, hasNextShort(int rad)

    • int rad – represents the radix used to manipulate as a short value.
    • int rad –表示用作短值的基数。

Return value:

返回值:

In both the cases, the return type of the method is boolean, it returns true when this Scanner next input as a short valid value otherwise it returns false.

在这两种情况下,方法的返回类型是布尔值 ,当这种扫描仪下一个输入的短有效值否则返回false返回true。

Example:

例:

// Java program is to demonstrate the example
// of hasNextShort() method of Scanner
import java.util.*;
import java.util.regex.*;
public class HasNextShort {public static void main(String[] args) {String str = "Java Programming! 3 * 8= 24";
Short val = 125;
str = str + val;
// Instantiates Scanner
Scanner sc = new Scanner(str);
while (sc.hasNext()) {// By using hasNextShort() method is to
// check whether this object next token
// represents short or not in the default
// radix
boolean status = sc.hasNextShort();
System.out.println("sc.hasNextShort(): " + status);
// By using hasNextShort(radix) method is to
// check whether this object next token
// represents short in the given radix
// or not
status = sc.hasNextShort(4);
System.out.println("sc.hasNextShort(2): " + status);
sc.next();
}
// Scanner closed
sc.close();
}
}

Output

输出量

sc.hasNextShort(): false
sc.hasNextShort(2): false
sc.hasNextShort(): false
sc.hasNextShort(2): false
sc.hasNextShort(): true
sc.hasNextShort(2): true
sc.hasNextShort(): false
sc.hasNextShort(2): false
sc.hasNextShort(): false
sc.hasNextShort(2): false
sc.hasNextShort(): true
sc.hasNextShort(2): false

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

java 方法 示例

java 方法 示例_Java扫描器具有示例的NextNextShort()方法相关推荐

  1. java 静态缓存示例_Java 9 JShell示例:集合静态工厂方法

    java 静态缓存示例 这篇文章继续从My My Java 9 Features博客文章中探索Java9功能. 在这里,我们在List,Set和Map接口中试验Java9 Collections静态工 ...

  2. java泛型方法 通配符_Java泛型教程–示例类,接口,方法,通配符等

    java泛型方法 通配符 泛型是Java编程的核心功能之一,它是Java 5中引入的.如果您使用的是Java Collections ,并且版本5或更高版本,则可以肯定使用了它. 将泛型与集合类一起使 ...

  3. java 示例_Java最终关键字示例

    java 示例 The final keyword in Java can be used with variables, methods, and classes. Java中的final关键字可以 ...

  4. java 生成随机数_Java 生成随机数的 N 种方法

    原标题:Java 生成随机数的 N 种方法 www.baeldung.com/java-generating-random-numbers 1.引言 本文将探讨用 Java 生成随机数的不同方法. 2 ...

  5. java反射方法调用_Java反射(3)调用方法

    目录: 1.访问方法(Method)对象的方法汇总 2.获取方法(Method)对象中的值 3.设置方法(Method)对象中的值 1.访问Method的方法汇总 以下四种方法在Class类可以返回关 ...

  6. java get方法使用_java中关于set()和get()方法的理解和使用

    java中 当定义了一个私有的成员变量的时候,若是须要访问或者获取这个变量的时候,就能够编写set或者get方法去调用.java set()是给属性赋值的,get()是取得属性值的 被设置和存取的属性 ...

  7. java泛型方法作用_java泛型的作用与使用方法是什么?

    泛型,即"参数化类型".一提到参数,最熟悉的就是定义方法时有形参,然后调用此方法时传递实参.那么参数化类型怎么理解呢?顾名思义,就是将类型由原来的具体的类型参数化,类似于方法中的变 ...

  8. java 随机数生成实现_Java中生成随机数的实现方法总结

    搜索热词 在实际开发工作中经常需要用到随机数.如有些系统中创建用户后会给用户一个随机的初始化密码.这个密码由于是随机的,为此往往只有用户自己知道.他们获取了这个随机密码之后,需要马上去系统中更改.这就 ...

  9. java private 接口_java接口中 定义 private 私有方法

    在传统的Java编程中,被广为人知的一个知识点是:java Interface接口中不能定义private私有方法.只允许我们定义public访问权限的方法.抽象方法或静态方法.但是从Java 9 开 ...

最新文章

  1. vs2003复制一个web窗体,没有更改指向同一个cs 文件,引发大问题
  2. 编码小记(未整理-持续更新)
  3. java 共享锁 独占锁_Java并发编程锁之独占公平锁与非公平锁比较
  4. sql case 语句
  5. 理解 Android 的 ONE_SHOT_MAKEFILE
  6. REST和RESTful有什么区别
  7. pytorch: 网络层参数初始化
  8. Doom启示录(三)------李乃峰所崇拜之 两个约翰!
  9. 如何高效率学习PMP?
  10. 西门子MM440变频器调试小记
  11. Python实现将图片转为Excel
  12. Python笔记03:python中用import导入包的机制原理是什么?
  13. ps cs6调油画效果教程
  14. 用5000字长文记录华为仓库服务GaussDB(DWS)上手过程【这次高斯不是数学家】
  15. coron 小娜_Win10小娜近乎报废!教你卸载毫无用处的Cortana
  16. IE浏览器连不上网电脑无法联网
  17. YARN中的任务队列调度器-容量调度器(Capacity Scheduler)
  18. 手机寸照如何修改底色
  19. Linux 文件系统
  20. 基于python pygame实现的雨点动画

热门文章

  1. 网站如何快速搭建即时响应客服系统
  2. python rtf转txt_将DOC、RTF格式文件批量转为TXT格式文件
  3. java语法定制混淆,由撇号混淆的textpad语法高亮显示
  4. linux+svn+拉取版本_在linux客户端下管理svn版本库
  5. Ocrad.js – JS 实现 OCR 光学字符识别
  6. 响应式布局 max-device-width 与 max-width 的区别
  7. 用CSS伪类制作一个不断旋转的八卦图?
  8. 【CSS】小妙招,各种问题总结方法处理
  9. codeforces 1136E-Nastya Hasn't Written a Legend
  10. C++ namespace