Sum All
Submit solution
Points:
40 (partial)
Time limit:
1.0s
Memory limit:
256M
Authors:
Problem types
Allowed languages
Java 19
題目說明
給一陣列長度,再輸入陣列的值
輸入限制:整數
vvv使用以下程式碼作答vvv
import java.util.Scanner;
public class SumAll {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] array = new int[n];
for (int i = 0; i < n; i++) {
array[i] = in.nextInt();
}
in.close();
// 傳陣列、長度到副程式,做加總
System.out.print(sum(array, n));
}
public static int sum(int[] array, int n) {
// 要執行的程式碼
// 記得return
}
}
輸入
1個整數
輸出
正整數
測試資料0 輸入
7
2 3 6 9 8 7 0
測試資料0 輸出
35
測試資料1 輸入
1
3
測試資料1 輸出
3
Comments
題解