In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how Scanner inputs numbers and strings in java. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Introduction to Scanner Class
Java 5 adds the java.util.Scanner class, a new utility for scanning input text. It is some kind of combination between the previous StringTokenizer and Matcher classes. Because any data must be retrieved through a capture group of the same pattern or by using an index to retrieve parts of the text. You can then combine regular expressions with methods to retrieve specific types of data items from the input stream. In this way, in addition to using regular expressions, the Scanner class can analyze data of string and basic types such as int and double at will. With Scanner, you can write a custom parser for any text content you want to work with.
Scanner input numbers, strings
The functions of package java05;import java.util.Scanner;//1, guide package / * Scanner class, which can be used to input data by keyboard and refer to the type in the program.
1. Guide package
2. Create
3. Use to get an int number entered by the keyboard, int num = sc.nextInt () to get a str string entered by the keyboard, String str = sc.next () * * / public class DemoScanner {public static void main (String [] args) {/ / create / / Note: System.in represents input from the keyboard Scanner sc = new Scanner (System.in); / / 3, get the int number entered by the keyboard int num = sc.nextInt () System.out.println ("the input number is:" + num); / / gets the keyboard input string String str = sc.next (); System.out.println ("the input string is:" + str);}}
Thank you for reading! This is the end of the article on "how to input numbers and strings in Scanner in java". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.