int nextInt()

描述 (Description)

java.util.Scanner.nextInt()方法将输入的下一个标记作为int进行扫描。对此方法nextInt()的调用与调用nextInt(radix)的方式完全相同,其中radix是此扫描仪的默认基数。

声明 (Declaration)

以下是java.util.Scanner.nextInt()方法的声明public int nextInt()

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回从输入中扫描的int

异常 (Exception)InputMismatchException - 如果下一个标记与Integer正则表达式不匹配,或者超出范围

NoSuchElementException - 如果输入用尽

IllegalStateException - 如果此扫描程序已关闭

例子 (Example)

以下示例显示了java.util.Scanner.nextInt()方法的用法。package com.iowiki;

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);

// find the next int token and print it

// loop for the whole scanner

while (scanner.hasNext()) {

// if the next is a int, print found and the int

if (scanner.hasNextInt()) {

System.out.println("Found :" + scanner.nextInt());

}

// if no int is found, print "Not Found:" and the token

System.out.println("Not Found :" + scanner.next());

}

// close the scanner

scanner.close();

}

}

让我们编译并运行上面的程序,这将产生以下结果 -Not Found :Hello

Not Found :World!

Found :3

Not Found :+

Not Found :3.0

Not Found :=

Not Found :6.0

Not Found :true

java int在那个包_int nextInt()相关推荐

  1. java int在那个包_int intValue()

    int intValue() 描述 (Description) java.lang.Double.intValue()方法将此Double的值作为int返回(通过强制转换为int类型). 声明 (De ...

  2. JAVA 中的代码生成包 CGLIB (Code Generation Library)

    JAVA 中的代码生成包 CGLIB (Code Generation Library) CGLIB 是一个功能强大,高性能的代码生成包.它为没有实现接口的类提供代理,为 JDK 的动态代理提供了很好 ...

  3. java中scanner中nextint_Java Scanner nextInt()方法与示例

    扫描仪类nextInt()方法 语法:public int nextInt(); public int nextInt(int rad);nextInt()方法在java.util包中可用. next ...

  4. java学习笔记(八)----包,jar文件

    包  //建立包后同一个文件中的类都属于这个包,所有的类都必须按包名所对应的目录,在硬盘中存放.同一个包中的类在相互调用时,是不用指定包名的.    ---在编译时对于下面这个类,用这样的方法  ja ...

  5. Java中的Atomic包使用指南

    转载自 http://ifeve.com/java-atomic/ 本文首发于并发网,作者:方腾飞 引言 Java从JDK1.5开始提供了java.util.concurrent.atomic包,方便 ...

  6. Eclipse中将java类打成jar包形式运行

    记录一次帮助小伙伴将java类打成jar包运行 1.创建java project项目 file > new > project > java project 随便起一个项目名称,fi ...

  7. java 执行shell 卡住_Aid learning/Termux之Jupyter的Java编程高级篇——包管理

    Aid Learning自从0.80版本开始就自带Jupyter了. Termux也可以安装Python,然后安装Jupyter,不过要想在Termux使用纯种Java,特别是Java使用Jupyte ...

  8. java生成cmd jar包_Java程序运行机制及cmd编译运行探究(二) cmd编译运行Java程序并打成jar包...

    目标:写一个RandomUtils.java工具类,返回一个随机数,并把这个类的字节码文件打成jar包 在Java运行机制及cmd编译运行探究(一)准备工作一文中,我总结了一部分要用到的cmd及编译运 ...

  9. ios apns netty java codec 防止粘包

    ios apns java codec 防止粘包 public Bootstrap newBootstrap(Bootstrap bootstrap,final PushHandler phandle ...

最新文章

  1. WinDbg 脚本实例,可以显示 SSDT
  2. VC++ 多文档模板(添加新文档模板)编程实例
  3. 2003 SERVER 本地连接 TCP/IP问题[转]
  4. UWP 显示图片到Image控件
  5. 大家注意:升级 win8.1 火狐浏览器 谷歌浏览器 搜狗五笔输入法 都不能用啦
  6. 命令行下Apache日志统计举例
  7. CES 2021落下帷幕 未来3年展会时间已公布
  8. hackbar 使用教程_hackbar简单安装使用教程
  9. [原创]Firefox扩展
  10. COSCon’19开源教育论坛:开源无疆、教育无界
  11. PLC基本指令系统优势
  12. 西直门立交桥的破事儿
  13. 代码质量检查规则中的 is provided externally to the method and not sanitized b.
  14. string类----猜词游戏
  15. oom killer理解和日志分析
  16. 【ACWing】671. DDD
  17. 电脑声音同步到手机,蓝牙耳机连接台式电脑另类解决方案
  18. python中写sql语句添加for循环和变量。(一种SQL引入循环的思想实现)
  19. AI研究者的方法论和工具箱|微软大牛独家「AI课程/资源/数据」
  20. Soft Actor-Critic 论文笔记

热门文章

  1. 宝石甲壳虫害怕什么?
  2. 基于机器学习聚类算法寻找美国职业篮球联赛NBA中的超级强队
  3. 使用纯H5开发手机app页面的一些经验
  4. ubuntu安装pylint
  5. excle转xml文件
  6. win11打开移动热点显示“我们无法设置移动热点”
  7. 向量内积和外积的计算以及意义
  8. type_traits
  9. javascript王国的一次旅行,一个没有类的世界怎么玩转面向对象?
  10. 阿里云SLB负载均衡理论与详细操作