Home > Java > javaTutorial > body text

How to input data from keyboard in java

PHPz
Release: 2023-06-02 11:34:06
forward
3064 people have browsed it

1. First import the java.until.Scanner class and then use it.

Input

Scanner i(任意) = new Scanner(http://System.in);
Copy after login

2. All numbers entered on the keyboard can be recorded. Different types of data need to be stored in different ways.

3. Use it when inputting int type data, such as age.

int[] age = i. next int();
Copy after login

4. The data entered at this time is stored in age.

5. Use when inputting floating point data.

double weight = I. nextDouble();
Copy after login

6. When inputting string type.

Strong name = I. next();
Copy after login

7. When entering bolean type.

boolean islove =i. next boolean();
Copy after login

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

Related labels:
source:yisu.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template