Home  >  Article  >  Java  >  How to input data from keyboard in java

How to input data from keyboard in java

PHPz
PHPzforward
2023-06-02 11:34:063022browse

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

Input

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

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();

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

5. Use when inputting floating point data.

double weight = I. nextDouble();

6. When inputting string type.

Strong name = I. next();

7. When entering bolean type.

boolean islove =i. next boolean();

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete