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!