Home > Back-end >  Consult a Java problem
Consult a Java problem

Time:10-04

O n the sum of nonnegative integers
Subject content:

Input nonnegative integer n, and output them, 1 & lt;=n<=100, while each number & lt; 800, does not meet the requirements of the input and output message: "error",



Input format:

Input consists of two lines, the first line, including an integer n, said a total of n number, the second line: contains n integers,



The output format:

Output n number and,



Input the sample:

4
1 2 3 4



The output sample:

10

CodePudding user response:

Public static void main (String [] args)
{
System. Out. Println (" the first line, including an integer n, said number, a total of n \ n the second line: contains n integers, separated by Spaces ");
Scanner input=new Scanner (System. In);
Int total=Integer. ParseInt (input. NextLine ());
String number=input. NextLine ();
String [] Numbers=number. The split (" \ \ s + ");
Int sum=0;
for (int i=0; I & lt; The total; I++)
{
The sum +=Integer. ParseInt (Numbers [I]);
}
System. The out. Println (sum);
}
  • Related