Problem Description:
Input Sample: 1 2 3 4 5 6
Output Sample: 1 2 3 4 5 6
Variable length, the data is entered with a space interval and the ENTER key is ended.
Solve the misunderstanding:
To solve the problem, have been thinking about the scanner class to get to ' \ n ' to jump out of the input loop
With several attempts, it is found that the next () method does not capture what you want to get.
Post-Program:
To end the entry of a string of data with the ENTER key, all data that needs to be entered must be one line, and the nextline () function can be used to obtain all.
See the following code:
Package blogtext;import java.util.arraylist;import java.util.scanner;public class Enter { public static void main (string[] args) { Scanner scanner=new Scanner (system.in); Arraylist<integer> arraylist=new arraylist<>(); String value=scanner.nextline (); String []nums=value.split (""); for (int i=0;i<nums.length;i++) {int temp=integer.parseint (Nums[i]), Arraylist.add (temp);} for (int i=0;i <arraylist.size (); i++) {System.out.println (Arraylist.get (i));}} }
The input of an indefinite length array is ended by a return key.