Java Scanner nextLine()方法与示例
扫描仪类nextLine()方法 (Scanner Class nextLine() method)
nextLine() method is available in java.util package.
nextLine()方法在java.util包中可用。
nextLine() method is used to get the skipped line.
nextLine()方法用于获取跳过的行。
nextLine() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
nextLine()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
nextLine() method may throw an exception at the time of returning a new line.
nextLine()方法在返回新行时可能会引发异常。
- NoSuchElementException: This exception may throw when no line exists.NoSuchElementException :不存在任何行时,可能引发此异常。
- IllegalStateException: This exception may throw when this Scanner is not opened.IllegalStateException :如果未打开此扫描器,则可能引发此异常。
Syntax:
句法:
public String nextLine();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of the method is String, it returns skipped line.
该方法的返回类型为String ,它返回跳过的行。
Example:
例:
// Java program to demonstrate the example
// of String nextLine() method of Scanner
import java.util.*;
public class NextLineOfScanner {public static void main(String[] args) {String str = "Hi, true \n IncludeHelp! 8 + 2.0f = 10.0f";
// Instantiate Scanner with the
// given str
Scanner sc = new Scanner(str);
// Display Scanner
System.out.println("sc.nextLine(): " + sc.nextLine());
// Display NextLine
System.out.println("sc.nextLine(): " + sc.nextLine());
// close the scanner
sc.close();
}
}
Output
输出量
sc.nextLine(): Hi, true
sc.nextLine(): IncludeHelp! 8 + 2.0f = 10.0f
翻译自: https://www.includehelp.com/java/scanner-nextline-method-with-example.aspx
Java Scanner nextLine()方法与示例相关推荐
- java scanner的hasnext,Java Scanner hasNext()方法
Java Scanner hasNext()方法 java.util.Scanner.hasNext() 方法如果此scanner有另一个标记在它的输入,则返回true.在等待要scanner的输入, ...
- java中scanner中nextint,Java Scanner nextInt()方法
Java Scanner nextInt()方法 java.util.Scanner.nextInt() 方法扫描输入的下一个标记为int.形式nextInt()方法的调用和调用nextInt(rad ...
- Java IOUtils.copy方法代码示例(亲测)
本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...
- Java Scanner.nextLine()读取回车问题解决
Scanner.nextLine读取回车问题解决 问题描述 问题分析 如何处理多出来的换行符 方法一 方法二 实战 问题解答 问题描述 我们在使用java读取键盘输入时,如果先读取一个int变量,再读 ...
- java中scanner中nextint_Java Scanner nextInt()方法与示例
扫描仪类nextInt()方法 语法:public int nextInt(); public int nextInt(int rad);nextInt()方法在java.util包中可用. next ...
- Java 中nextLine()方法没有执行直接跳过解决办法
使用Java的Scanner类nextLne()方法从显示器输入数据时,nextInt()后面的nextLine()直接跳过没有执行: 截图:第三个输入直接跳过 通过上网的查找我终于发现了问题出在哪里 ...
- java user directory,Java ProcessBuilder directory()方法与示例
语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...
- Java序列化魔术方法及其示例使用
在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...
- catalog java,Java Connection getCatalog()方法与示例
通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...
最新文章
- 数据中心的7个新兴发展趋势
- Python虚拟环境pyenv、venv(pyvenv)、virtualenv之间的区别,终于搞清楚了!
- 如果你恨一个程序员,忽悠他去做iOS开发
- 安卓系统使用摄像头API
- Linux Top使用说明
- CentOS GRUB引导错误无法进入系统解决办法
- CentOS 5.8/6.7若干优化
- ubuntua安装chrome_Ubuntu 16.04下安装64位谷歌Chrome浏览器
- 从开始的一无所有到现在的_我有房有车有高薪,凭什么娶一个“一无所有”的女人?...
- 数据库周刊55丨2021年1月数据库排行榜出炉;openGauss荣获“2020年度国产数据库”称号;易鲸捷喜获“金鼎奖”;搭建Mysql MGR高可用集群;openGauss主备部署;AWR分析办法
- ImageOptim 图片压缩工具
- 2022年信息系统监理师考试大纲
- 图片批量转换为base64
- 计算机博士复试英语自我介绍,博士复试自我介绍中英文
- 彩云之巅(一) 回忆的牵绊
- 滴滴android wear,滴滴货运app下载_滴滴货运apk最新安卓版下载v5.4.0_3DM手游
- java jmf播放mp3_关于jmf不能播放mp3的问题解决
- 模拟集成电路笔记 | 第三部分 | Chapter 5-6
- python火车抢票_春运火车票太难抢?不如试试这个python开源工具吧
- 【matlab】GMSK高斯最小频移键控
热门文章
- 常用命令_GIT常用命令大全
- weblogic命令行操作
- Spark初识-Spark与Hadoop的比较
- MIP 与 AMP 合作进展(3月7日)
- 我的女朋友漏电了–论C++中的失败(failure),缺陷(bug)和异常(exception)
- 阿里云服务器配置开发环境第五章:Centos7.3切换为iptables防火墙
- HashMap get不出对象时出错 解决
- [翻译] Haneke(处理图片缓存问题)
- 转载:MySQL数据库INSERT、UPDATE、DELETE以及REPLACE语句的用法详解
- asp.net本质论——HttpModule