114-1程設B組Week8實習課小考第一題
Submit solution
Points:
50 (partial)
Time limit:
10.0s
Memory limit:
977M
Authors:
Problem type
Allowed languages
Java 19, Java 8
題目說明
- 輸入多個整數,以
0作為結束。 - 請分別計算這些輸入的數值(不含
0)中所含正數個數、負數個數、總和及平均值。
測資範圍
\[ -10 <= 輸入的整數 <= 10\]
提醒
- 平均值變數以
double宣告。 - 平均值統一
四捨五入到整數,使用Math.round()。 - 冒號
:為英文半形。 - 最後一行要用
System.out.println()才會跟範例輸出一樣。 - 程式前面記得加上
import java.util.Scanner; - 輸入輸出請參考範例。
範例輸入/輸出
範例輸入1
-3
8
-10
6
9
0
範例輸出1
正數個數:3
負數個數:2
總和:10
平均值:2.0
範例輸入2
0
範例輸出2
正數個數:0
負數個數:0
總和:0
平均值:0.0
範例輸入3
-9
5
-7
1
-5
0
範例輸出3
正數個數:2
負數個數:3
總和:-15
平均值:-3.0
Comments
import java.util.Scanner; public class a2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int i = 0; int p = 0; int b = 0; int n = 0; int r = 0; int a=0;
}