Java基础 Scanner 使用nextLine接收字符串
- JDK :OpenJDK-11
- OS :CentOS 7.6.1810
- IDE :Eclipse 2019‑03
- typesetting :Markdown
code
package per.jizuiku.base;
import java.util.Scanner;
/**
* @author 给最苦
* @date 2019/06/29
* @blog www.cnblogs.com/jizuiku
*/
class Demo {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String myStr = sc.nextLine();
System.out.println("resut:" + myStr);
sc.close();
}
}
result
hello world
resut:hello world
sourceCode
/**
* Advances this scanner past the current line and returns the input
* that was skipped.
*
* This method returns the rest of the current line, excluding any line
* separator at the end. The position is set to the beginning of the next
* line.
*
* <p>Since this method continues to search through the input looking
* for a line separator, it may buffer all of the input searching for
* the line to skip if no line separators are present.
*
* @return the line that was skipped
* @throws NoSuchElementException if no line was found
* @throws IllegalStateException if this scanner is closed
*/
public String nextLine() {
modCount++;
if (hasNextPattern == linePattern())
return getCachedResult();
clearCaches();
String result = findWithinHorizon(linePattern, 0);
if (result == null)
throw new NoSuchElementException("No line found");
MatchResult mr = this.match();
String lineSep = mr.group(1);
if (lineSep != null)
result = result.substring(0, result.length() - lineSep.length());
if (result == null)
throw new NoSuchElementException();
else
return result;
}
resource
- [ JDK ] openjdk.java.net
- [ doc - 参考 ] docs.oracle.com/en/java/javase/11
- [ 规范 - 推荐 ] yq.aliyun.com/articles/69327
- [ 规范 - 推荐 ] google.github.io/styleguide
- [ 源码 ] hg.openjdk.java.net
- [ OS ] www.centos.org
- [ IDE ] www.eclipse.org/downloads/packages
- [ 平台 ] www.cnblogs.com
感谢帮助过 给最苦 的人们。
Java、Groovy和Scala等基于JVM的语言,优秀,值得学习。
规范的命名和代码格式等,有助于沟通和理解。
JVM的配置、监控与优化,比较实用,值得学习。
Java基础 Scanner 使用nextLine接收字符串的更多相关文章
- Java基础 Scanner 使用nextInt接收整数
JDK :OpenJDK-11 OS :CentOS 7.6.1810 IDE :Eclipse 2019‑03 typesetting :Markdown code ...
- java中Scanner类nextLine()和next()的区别和使用方法
转载:http://blog.csdn.net/zhiyuan_ma/article/details/51592730 在实现字符窗口的输入时,很多人更喜欢选择使用扫描器Scanner,它操作起来比较 ...
- Java基础教程(20)--数字和字符串
一.数字 在用到数字时,大多数情况下我们都会使用基本数据类型.例如: int i = 500; float gpa = 3.65f; byte mask = 0xff; 然而,有时候我们既需要 ...
- java基础——Scanner的基础和进阶
Scanner对象 目的:用来获取用户的输入 基本语法: Scanner s = new scanner (System.in); 通过Scanner 类的next()和nextLine()方法,获取 ...
- 解决一个无聊的问题,如何处理Java用户在dos被收集信息时拷贝带换行符的文本信息造成的while的多次循环(java解决Scanner.next在接收用户输入时出现多个换行的形况)[解决方案一]
问题描述: 用户在dos窗口输入的时候(web项目不会出现这样的问题,所以这个问题日常碰不到),摁下回车时,Scanner对象的next()扫描用户输入的文本,后面就可以根据输入的字符串进行判断,并执 ...
- java基础知识(二)字符串处理
字符串是程序开发中使用最为频繁,因此为了工作的高效和作为一名想进阶的程序员,了解并掌握字符串的处理显得尤为重要.java为我们提供了String.StringBuffer.StringBuilde三个 ...
- java中Scanner的nextLine()和next()的区别
首先,next()一定要读取到有效字符后才可以结束输入,对输入有效字符之前遇到的空格键.Tab键或Enter键等结束符,next()方法会自动将其去掉,只有在输入有效字符之后,next()方法才将其后 ...
- java===java基础学习(4)---字符串操作
java中的字符串操作和python中的大致相同,需要熟悉的就是具体操作形式. 关于具体api的使用,详见:java===字符串常用API介绍(转) package testbotoo; public ...
- Java基础笔记(十一)—— 字符串与数组
字符串的声明与初始化主要两种:String s1=new String("abc"); 或 String s2="abc"; String ...
随机推荐
- netty websocket
1 全局保存websocket的通道 NettyConfig.java public class NettyConfig { public static ChannelGroup group = n ...
- Codeforces J. A Simple Task(多棵线段树)
题目描述: Description This task is very simple. Given a string S of length n and q queries each query is ...
- linux系统编程之文件与io(四)
今天继续学习文件与io,主要是学习文件共享及文件.复制文件描述符,有点抽象,主要是概念上的理解,但是很重要,下面一一来分解: 文件共享: 回顾一下,在linux系统调用中,是通过文件描述符来访问文件的 ...
- jquery手机触屏滑动拼音字母城市选择器代码
今天用到城市选择,直接用拼音滑动方式来选择,用的时候引入jquery(个别样式需要自己修改) <div class="yp_indz"><img src=&quo ...
- 关于JS变量和作用域详解
ECMAScript 变量: 1.基本类型值(简单数据段) 2.引用类型值(可能由过个值构成的对象) → 保存在内存中的对象 ------ 动态属性: 只能给引用型值动态添加新属性,以便将来使用. - ...
- 洛谷 P1199 三国游戏 题解
每日一题 day18 打卡 Analysis 贪心 假如小A先选最大的[5,4],虽然电脑必须选一个破坏, 我们可以理解为5和4都属于小A的,假如后面未被破坏的最大值无论是和5相关还是和4相关,必然还 ...
- 一张图理解shell内核
#!/bin/bash name="liu de hua";#name后面=不能有空格 echo "hello word ${name}work $name"; ...
- 洛谷 P2791 幼儿园篮球题
洛谷 P2791 幼儿园篮球题 https://www.luogu.org/problemnew/show/P2791 我喜欢唱♂跳♂rap♂篮球 要求的是:\(\sum_{i=0}^kC_m^iC_ ...
- C++中unique函数的用法总结
个人感觉,unique是STL中很实用的函数之一,需要#include,下面来简单介绍一下它的作用. unique的作用是"去掉"容器中相邻元素的重复元素,这里去掉要加一个引号,为 ...
- 交互设计算法基础(3) - Quick Sort
int pivotIndex, pivot, swapIndex; void swap(int[] arr, int x, int y) { int temp = arr[x]; arr[x] = a ...