Find the sum of some integers. The first line of each test case will contain an integer n, which gives the number of integers in the array and the next n line(s) contain the integers
input 1#: 5 1 2 3 4 5
output: 15
input 2#: 2 12 12
output: 24
code:
public class Solution {
public static void main(String args[] ) throws Exception {
Scanner scanner= new Scanner(System.in);
{
int n[]= {5,1,2,3,4,5};
int tempobj=n[0];
int sum=0;
for(int i=1;i<=tempobj;i++)
{
sum= sum+n[i];
}
System.out.println(+sum);
}
}
}
This code only satisfies the first output. But not the second one. How should I define the array so that can I satisfy the other output when the same code is complied second time?