aiLabel:

Usage of Scanner Class in Java

The sea is in the sun
Favorable reply

The Scanner class in Java can help us receive data input from the keyboard. The following is an example program that Bing brought me.

Operation method

First, we create a ScannerDemo class with a class name under a java project.

Then we create a Scanner class object to receive the data input from the keyboard.

Here we use the nextLine method to receive strings. The next method can also obtain strings. However, the next method cannot obtain blank spaces. For example, if you enter Hello World, you can only get Hello using the next method while you can get the complete Hello World using the nextLine method. Because the nextLine method ends with the Enter key.

Right click in the blank area of the program window and select Run As -- Java Application

At this time, in the console, enter a string and press Enter. You can see that the string is successfully received using the nextLine of the Scanner class.

Of course, in addition to receiving strings, Scanner can also receive integer and floating point numbers, which have corresponding methods. Let's take receiving integers as an example. Other types are also similar. Let's try it yourself.

Run to view the results. You can see that nextInt() can only receive integers. If you want to receive other types of data, you have to use other methods. If you don't understand, you can go to the document.

The sea is in the sun 2024-05-22 16:20:13
The above contents quoted, excerpted or reproduced on this website are only for the exchange or reference of website visitors. The views or information in the text have nothing to do with Aiwen, and any matters and legal liabilities related to it have nothing to do with Aiwen.

Latest answers Change

one

Q: What are the effects of shrimps

Answer:
A: Shrimp can help people maintain their own immune function and promote their growth and development. Shrimp is a high protein food, which is rich in calcium, magnesium, potassium and other minerals. These nutrients are essential to the human body. Eating shrimps can supplement certain nutrients for the body and maintain normal physiological functions of the human body.
two

Arrhenius formula 2020-07-20

Related recommendations

What is the height and weight standard of 1.7 meters

According to the principle that a certain height has a corresponding ideal weight, the standard weight can be inferred from the actual height. The modified Brcoa formula is commonly used in China, and its calculation method is as follows: male: standard weight=(height - 100) × 0.90 female: standard weight=(height
Details>
Question time: January 22, 2020

Which are the four major airlines in China

The four major airlines in China are Air China, China Southern Airlines, China Eastern Airlines and Hainan Airlines. 1. Air China Limited, or Air China for short, was officially established in Beijing in 1988
Details>
Question time: August 24, 2021

Is Zhuoma Tile Whole Body

Zhuoma tiles are all in one. Ceramic tile is a kind of acid and alkali resistant ceramic or stone material formed by grinding, mixing, pressing, glazing and sintering refractory metal oxides and semi metal oxides. Building or decorative materials are called ceramic tiles. Its raw materials are mostly
Details>
Question time: July 18, 2020

How many counties and cities are there in Weifang

There are 16 counties and cities in Weifang. It governs 8 districts, 6 county-level cities and 2 counties. Kuiwen, Weicheng, Hanting and Fangzi are four municipal districts. Linqu and Changle counties. In charge of 6 county-level cities, namely Qingzhou, Zhucheng, Shouguang, Anqiu, Gaomi and Changyi. In addition: Gao
Details>
Question time: February 19, 2020

How to install a computer system for a novice

1、 Preparation for reinstallation 1. The current system can run, or you need to use a USB flash disk 2. Back up the C disk and important desktop files to avoid data loss 2. The steps for reinstallation of the computer system are as follows: 1. Use the decompression tool to decompress the computer system image to a partition outside of the C disk, such as the D disk
Details>
Question time: November 3, 2019

What is the concept of a book

The concept of "one book": "one book" (college entrance examination enrollment batch) generally refers to the national unified examination enrollment batch (college entrance examination enrollment batch) of ordinary colleges and universities. In September 2014, the Implementation Opinions on Deepening the Reform of the Examination and Enrollment System issued by the State Council proposed to create
Details>
Question time: August 2, 2020

What kind of hook do you use to fish with shrimp

Use No. 8 Maruti hook for shrimp fishing instead of explosive hook. Then you can choose the shrimp hook gun, and pass the hook tip through the border between the gun position and the head shell. The hook should be shallow, and the hook position should be as far away from the viscera in the head shell as possible. Or hook shrimp gills. The shrimp gills are located on both sides of the head shell near the bottom
Details>
Question time: May 14, 2020

Can Self heating Hot Pot Take the Train

Yes, generally no problem. 1. At present, there is no explicit regulation that self heating hot pot cannot be taken on the train, and many consumers have also taken self heating hot pot on the train. 2. However, when using self heating hot pot on the train, you must pay attention to safety, because the bottom of self heating hot pot is added with
Details>
Question time: April 10, 2019

What does Guangxi local special plan mean

Guangxi local special plan refers to the special plan for Guangxi universities to recruit rural students in the implementation area. Generally, it is only a provincial key university, after the national special batch. The local special plan aims to recruit rural students from all provinces and cities. Local special programs and colleges and universities
Details>
Question time: August 10, 2020

How to track men's swordsmanship

Press R to hide. You can move. After a while, the throwing knife will automatically return. Then, depending on the situation, chase the enemy and Q onto others. Then move to control the position. When the throwing knife comes back, it can pass through the target and inflict a lot of damage. If it is to escape, it can run stealthily. During the period, you don't have to
Details>
Question time: November 11, 2019

How to remove the white hairtail

The removal method of the white matter on the hairtail is: first defrost the hairtail in a water basin, and then wipe it with a steel wire ball from end to end. Hairtail belongs to Scleroderma, Perciformes, Hairtail Family in Chordata, also called skirt girdle, fat girdle, oil girdle, tooth girdle, etc. It is ferocious
Details>
Question time: February 17, 2020

Why text ten 86

The reason for sending SMS No. 1086 is that this is China's number access, the call display of the communication network will be displayed together with the country code, and "+86" is the international area code of China; And the country code of China is played in China, so "+86" is not required. SMS is short for SMS
Details>
Question time: March 23, 2020

Can I use a comb to comb pear blossom perm

It can be combed when wet, but not when the hair is dry. When the hair is dry, it will be tight, difficult to comb, and it is easy to hurt the hair. When you wash your hair, you must use conditioner after using shampoo (must be used). After applying conditioner, use your fingers instead of combs to comb your hair
Details>
Question time: November 13, 2019

What's the meaning of 10 yuan for 10 shares to 7 shares

It means that the company uses the capital reserve to increase 7 shares for every 10 shares of shareholders, which can be understood as free "gift" of 7 shares to you, as well as the use of undistributed profits to distribute cash dividends of 10 yuan for every 10 shares (the 10 yuan is tax inclusive). Note that the 10 shares of cash dividends are not converted
Details>
Question time: June 16, 2020