search
HomeJavaJavaBaseHow to enter an array from the keyboard in java

How to enter an array from the keyboard in java

Dec 05, 2019 pm 01:18 PM
javaarrayenterkeyboard

How to enter an array from the keyboard in java

Related knowledge description:

java.util.Scanner is a new feature of Java5. We can obtain user input through the Scanner class.

nextLine()Function:

1. Enter is the end character, which means that the nextLine() method returns all characters before entering.

2. Can get blank space.

Online video tutorial sharing: java online learning

Examples are as follows:

public class exchangeNum {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
            String str=scanner.nextLine();
            String[] Arrays=str.split(",");   //通过“,”分离
            int[] a=new int[Arrays.length];
            for(int i=0;i<a.length;i++){
                a[i]=Integer.parseInt(Arrays[i]);   //将String型转化成int型
                System.out.print(a[i]+" ");
                }
        }
    }

Related article tutorial recommendations:java introductory learning

The above is the detailed content of How to enter an array from the keyboard 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.