Home>Article>Java> How to import scanner in java

How to import scanner in java

little bottle
little bottle Original
2019-05-21 16:24:13 15315browse

java.util.Scanner is a new feature of Java5, which is a new utility for scanning input text. Scanner is some combination between the previous StringTokenizer and Matcher classes. Since any data must be retrieved through capturing groups of the same schema or by using an index to retrieve individual parts of the text.

How to import scanner in java

You can then use regular expressions in conjunction with methods for retrieving specific types of data items from the input stream. In this way, in addition to using regular expressions, the Scanner class can also analyze data of strings and basic types (such as int and double) arbitrarily. With Scanner, you can write a custom parser for any text content you want to process.

import java.util.Scanner;

Add the above command to the location below the import package.

The following is the basic syntax for creating a Scanner object:

import java.util.Scanner; //导入Scanner包 public class ScannerDemo { public static void main(String[] args) { Scanner scan = new Scanner(System.in); // 从键盘接收数据 // next方式接收字符串 System.out.println("next方式接收:"); // 判断是否还有输入 if (scan.hasNext()) { String str1 = scan.next(); System.out.println("输入的数据为:" + str1); } scan.close(); }}

Related learning recommendations:java basic tutorial

The above is the detailed content of How to import scanner in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn