当前位置:网站首页>Basic usage of scanner
Basic usage of scanner
2022-06-12 14:25:00 【Happy happy】
**
Be careful Next and NextLine The difference between
**- Next See the space symbol end
- NextLine See the end of the carriage return symbol **
**Next Usage code example for
package base;
import java.util.Scanner;
public class Demo05 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Create a scan object to receive keyboard data
System.out.println(" Use next Method acceptance :");
// Judge whether the user has entered characters
if(scanner.hasNext()){
String str = scanner.next();
System.out.println(" The input content is :"+str);
}
scanner.close();
}
}
D:\apps\jdk8\bin\java.exe "-javaagent:E:\javanote\IntelliJ IDEA Community Edition 2021.1\lib\idea_rt.jar=52726:E:\javanote\IntelliJ IDEA Community Edition 2021.1\bin" -Dfile.encoding=UTF-8 -classpath D:\apps\jdk8\jre\lib\charsets.jar;D:\apps\jdk8\jre\lib\deploy.jar;D:\apps\jdk8\jre\lib\ext\access-bridge-64.jar;D:\apps\jdk8\jre\lib\ext\cldrdata.jar;D:\apps\jdk8\jre\lib\ext\dnsns.jar;D:\apps\jdk8\jre\lib\ext\jaccess.jar;D:\apps\jdk8\jre\lib\ext\jfxrt.jar;D:\apps\jdk8\jre\lib\ext\localedata.jar;D:\apps\jdk8\jre\lib\ext\nashorn.jar;D:\apps\jdk8\jre\lib\ext\sunec.jar;D:\apps\jdk8\jre\lib\ext\sunjce_provider.jar;D:\apps\jdk8\jre\lib\ext\sunmscapi.jar;D:\apps\jdk8\jre\lib\ext\sunpkcs11.jar;D:\apps\jdk8\jre\lib\ext\zipfs.jar;D:\apps\jdk8\jre\lib\javaws.jar;D:\apps\jdk8\jre\lib\jce.jar;D:\apps\jdk8\jre\lib\jfr.jar;D:\apps\jdk8\jre\lib\jfxswt.jar;D:\apps\jdk8\jre\lib\jsse.jar;D:\apps\jdk8\jre\lib\management-agent.jar;D:\apps\jdk8\jre\lib\plugin.jar;D:\apps\jdk8\jre\lib\resources.jar;D:\apps\jdk8\jre\lib\rt.jar;E:\javanote\out\production\Hello base.Demo05
Use next Method acceptance :
hello world
The input content is :hello
Process finished with exit code 0
Note the space in the middle above
**
NextLine Use
**
package base;
import java.util.Scanner;
public class Demo06 {
public static void main(String[] args) {
Scanner scanner= new Scanner(System.in);
System.out.println(" Use nextline Method ");
if (scanner.hasNextLine()){
String str = scanner.nextLine();
System.out.println(" The input is :"+str);
}
scanner.close();
}
}
D:\apps\jdk8\bin\java.exe "-javaagent:E:\javanote\IntelliJ IDEA Community Edition 2021.1\lib\idea_rt.jar=52700:E:\javanote\IntelliJ IDEA Community Edition 2021.1\bin" -Dfile.encoding=UTF-8 -classpath D:\apps\jdk8\jre\lib\charsets.jar;D:\apps\jdk8\jre\lib\deploy.jar;D:\apps\jdk8\jre\lib\ext\access-bridge-64.jar;D:\apps\jdk8\jre\lib\ext\cldrdata.jar;D:\apps\jdk8\jre\lib\ext\dnsns.jar;D:\apps\jdk8\jre\lib\ext\jaccess.jar;D:\apps\jdk8\jre\lib\ext\jfxrt.jar;D:\apps\jdk8\jre\lib\ext\localedata.jar;D:\apps\jdk8\jre\lib\ext\nashorn.jar;D:\apps\jdk8\jre\lib\ext\sunec.jar;D:\apps\jdk8\jre\lib\ext\sunjce_provider.jar;D:\apps\jdk8\jre\lib\ext\sunmscapi.jar;D:\apps\jdk8\jre\lib\ext\sunpkcs11.jar;D:\apps\jdk8\jre\lib\ext\zipfs.jar;D:\apps\jdk8\jre\lib\javaws.jar;D:\apps\jdk8\jre\lib\jce.jar;D:\apps\jdk8\jre\lib\jfr.jar;D:\apps\jdk8\jre\lib\jfxswt.jar;D:\apps\jdk8\jre\lib\jsse.jar;D:\apps\jdk8\jre\lib\management-agent.jar;D:\apps\jdk8\jre\lib\plugin.jar;D:\apps\jdk8\jre\lib\resources.jar;D:\apps\jdk8\jre\lib\rt.jar;E:\javanote\out\production\Hello base.Demo06
Use nextline Method
hello world
The input is :hello world
Process finished with exit code 0
边栏推荐
- Unhandled exception stack overflow
- 完美收官|详解 Go 分布式链路追踪实现原理
- IAT hook hijacking process API call
- C語言中主函數調用另外一個函數,匯編代碼理解
- Printing colored messages on the console with printf
- 3. Hidden processes under the ring
- [MySQL] basic database operation
- Why do Chinese programmers change jobs?
- Wait function in SystemC
- 工具笔记 —— 常用自定义工具类(正则,随机数等)
猜你喜欢

Notepad common settings

Player actual combat 25 unpacking module add close

Postgresql14 installation and use tutorial

注重点击,追求更多用户进入网站,可以选择什么出价策略?

Shell脚本到底是什么高大上的技术吗?

After reading the question, you will point to offer 16 Integer power of numeric value

Two methods of QT using threads

Reverse order of Excel

Player actual combat 13 create qtopengl project to promote window control and reload qoopenglwedge

Player practice 18 xresample
随机推荐
Why do Chinese programmers change jobs?
[MySQL] basic database operation
Visual studio common shortcuts
Notepad common settings
【OCR】AspriseOCR C# 英文、數字識別(中文不行)
Player practice 20 audio thread and video thread
Leetcode 2176. 统计数组中相等且可以被整除的数对
Word insert picture blocked by text
How to set, reset and reverse bit
Analysis of lua source code
Implementation and debug of process hiding under x64
Tool notes - common custom tool classes (regular, random, etc.)
Single bus temperature sensor 18B20 data on cloud (Alibaba cloud)
Introduction to database system (Fifth Edition) notes Chapter 1 Introduction
Vs2012: cannot assign a value of type 'char *' to an entity of type 'lpwstr'
Two methods of QT using threads
Leetcode questions brushing February /1020 Number of enclaves
对于跨境电商,更侧重收入的出价策略 —Google SEM
C secret script Chapter 1: data storage (in-depth analysis)
QA of some high frequency problems in oauth2 learning