加入偶數判斷式~~
/ l \ k7 K, w4 \5 H& k5 h& Opublic class TQC207 {
% n C5 | V$ r, B: }! ]4 h% G8 L& y
: l6 [2 Y5 ]: ?, s- N7 ?% x public static void main(String[] args) {, c+ ]3 {0 I5 x" o
int sum = 0;7 f% r/ c. M% h
int odd = 0;& ]: i( O& H0 U7 f2 f& g. D
int max = 0;1 M$ Q: h3 `$ h. V' I
int tmp = 0;/ @3 y: f) C, S7 W
int even = 0;
2 ^' J3 [: s- X2 M+ j int[] nums = new int[args.length];
4 _+ o- C' n& y* q7 i* Y4 N( q. k System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
) |0 ^" O1 v$ }, O, T" Y try {
- ^* K8 H+ B: y$ w! u. t$ O" k0 F for (int i = 0; i < args.length; i++) {
0 Z; i$ P# d, ~+ k tmp = Integer.parseInt(args[i]);
7 i' g+ @5 r/ b nums[i] = tmp;9 s( K6 \# A2 S& G
sum += tmp;
) n8 ^5 c9 b! w v: M8 R# F if (tmp % 2 == 0) {
$ U' y: C4 i$ w: K even++;
+ l8 Q: W, [3 X8 B$ F0 _& L6 N } q' Y/ K" ~% W8 i' V9 E
if (tmp % 2 != 0) {
) z M. u% f e" g c odd++;
/ h1 N: G8 W3 |& H& o/ d }& P3 ^* @$ t, g, s# {# ]% N7 Y
max = Math.max(tmp, max);
. o5 n9 C4 R/ V0 k+ H }8 }2 u7 p% Y/ F7 ]) L% i
System.out.println("最大值" + max);
, N; j# y8 C, p! U System.out.println("奇數" + odd);! y/ X$ i' {, p% z/ W% D' Q
System.out.println("偶數" + even);! f$ d& {+ J3 w; D+ m8 S2 Z
System.out.println("總和" + sum);- |; J, i" X. f2 [
} catch (Exception e) {2 [0 [) \/ `1 b# l2 _
System.out.println("輸入錯誤");
0 T3 {" B7 ~1 H) Q- x" X% i }; n- q) Q2 K' G4 y8 {
7 ]7 P2 U6 g7 G% y, B8 k0 N. m
}
5 }! R$ Q" T; {) a3 g# ?* |# O, G0 T) v
} |