加入偶數判斷式~~9 a. G9 C( U1 p* g
public class TQC207 {, c3 l$ F# F6 T0 p
. x& c U9 _, B
public static void main(String[] args) {5 z+ S* W* R+ D. \
int sum = 0;& D+ _# y. [- d0 `
int odd = 0; p, w; ?: Y* l. Z; j2 {
int max = 0;, N" T( k2 Z* c. j2 T5 t
int tmp = 0;
9 H6 e* A0 r* y6 B7 e! n/ w int even = 0;3 w3 O1 `% X5 g
int[] nums = new int[args.length];9 t7 e% i3 @ L! e0 [& j
System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
, ~6 l" ?6 g( ^/ o) X try {
/ p3 Y/ O; u2 J& t8 N+ D" R& ~ for (int i = 0; i < args.length; i++) {# T2 T# x) R! T# L
tmp = Integer.parseInt(args[i]);6 o* w8 }) K. o3 t* U$ J) V: K
nums[i] = tmp;% _. y8 B- s( ]8 `$ E1 \
sum += tmp;) K; r# P; f, C9 L
if (tmp % 2 == 0) {1 r/ G( W# W" m$ L6 t* g2 Y
even++;
. s- l2 \+ [/ d6 l$ `6 W }
$ e3 _) H. [( w/ n7 p( T2 m9 M) g if (tmp % 2 != 0) {) x# L" m) h+ t- Y; C
odd++;; |& I! g% z$ @/ r' A
}* E% S/ D- m. c0 C1 E1 I3 x
max = Math.max(tmp, max);
% F! Q& A5 k0 m) p7 `; H0 M( ^ }2 O- e! U; I; H6 Z
System.out.println("最大值" + max); a% \ n a/ n5 b9 L
System.out.println("奇數" + odd);
/ ?4 e+ U7 N- O" n/ }0 i$ { System.out.println("偶數" + even);1 V. ]- d1 |- T K& l# k7 h
System.out.println("總和" + sum);
1 ~+ o9 ^7 U/ `( w! ]2 h } catch (Exception e) {/ t9 ~) a1 w! e; `1 c; \' B
System.out.println("輸入錯誤");: h8 D7 w a- G4 q
}
/ J' _/ T. ^8 _
6 l; m% @7 \: g }* ~ K0 h3 I; O' B
- e9 B% |- d7 f& @6 h: j} |