Nextint () reads only numbers, but line breaks do not,
When nextint () is used, it must be a numeric character, followed by a line break and nextline (). It ends when the line Delimiter is read, and there is no information before the line separator, therefore, no information can be returned.
Import Java. util. sums; public class sum {/*** @ Param ARGs */public static void main (string [] ARGs) {int n = 0; string S1; scanner S = new partition (system. in); n = S. nextint (); // S1 = S. nextline (); the addition of this sentence is very different from the addition of this sentence. // system. out. println ("N:" + n); int S2 [] = new int [N]; for (INT I = 0; I <n; I ++) {S1 = S. nextline (); S2 [I] = getlinesum (S1) ;}for (INT I = 0; I <n; I ++) {system. out. println (s2 [I]) ;}} public static int getlinesum (string strline) {second s = new second (strline); int sum = 0; while (S. hasnextint () {sum + = S. nextint () ;}return sum ;}}
If no value is added in the marked Red Area
s1=s.nextLine();
Result:
2
1 3
0
4
The result is as follows:
2
1 3
2 4
4
6
The cause of the problem has been explained at the beginning. Pay attention to this simple input/output format.