Java input and output issues review

Many questions are asked to enter the program number represents the number of digits, then the integer input line separated by a space, the input of each line with nextLine read reconverted int, which split in the "\\ s +" represents at least one space, "\\ s" represents a space

Code

 1     public static void main(String[] args) {
 2        
 3        Scanner in = new Scanner(System.in);
 4         String n = in.nextLine();
 5         int size = Integer.parseInt(n);
 6 ;       
 7         String array = in.nextLine(); 8 String[] c = array.split("\\s+"); 9 10 int[] num = new int[size]; 11 12 for(int i=0;i<size;i++) { 13 num[i] = Integer.parseInt(c[i]); 14  } 15 16 for(int i = 0; i < size; i++){ 17 System.out.print(num[i]+1); 18 System.out.print(' '); 19  } 20  in.close(); 21 22 }

Input:

4

1 2 3 4

Output:

2 3 4 5

Guess you like

Origin www.cnblogs.com/TFYu/p/11298941.html