加入偶數判斷式~~
* r" v- }7 C9 z% ?% S+ c" Dpublic class TQC207 {" }9 e/ F& K& b/ ]
M# x3 a$ l4 t# D9 V9 z5 [ public static void main(String[] args) {
, [% T8 Y; T s, S: u9 r" G int sum = 0;
, b( x* c1 ]6 H7 D3 i) ^: ~; o int odd = 0;7 S, Y, o1 d+ v v- Q4 a
int max = 0; Q* [" j3 s5 @- G. ]0 {
int tmp = 0;; V, E% c% c/ B4 z$ Y
int even = 0;
" z) S, k7 u5 x- x: \ int[] nums = new int[args.length];
% x! H. T+ P0 t1 y System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
/ J( B8 D5 r; a c: ~ try {
7 r( i* Y* I; l# w0 `3 y for (int i = 0; i < args.length; i++) {
0 s; K; y+ n2 y9 i tmp = Integer.parseInt(args[i]);: e! j8 m1 L' i2 z. y& \
nums[i] = tmp;, h3 P8 o& P" B a' P
sum += tmp;
: Z6 Q4 K" c3 i3 q$ g% ]' i if (tmp % 2 == 0) {) C. b3 |/ j+ A; X. R
even++; r0 S! I* x/ ?- J# L# m4 U
}
7 } J. l) ~+ Q5 j if (tmp % 2 != 0) {1 D& `+ P& k4 ]7 f1 A
odd++;
4 Q1 _$ _. e3 @* u; j# q% t6 Z9 x }
0 y9 T4 s( b- f max = Math.max(tmp, max);
1 |5 I) t. M+ M( Y: s }
: c S3 c$ N; c h System.out.println("最大值" + max);' A; @+ E; x. e+ Y7 w
System.out.println("奇數" + odd);
' E( P/ Z! R0 t! Q, N3 Z System.out.println("偶數" + even);
$ d9 F5 ?: ]9 C! \% K# y System.out.println("總和" + sum);
+ z" \8 k3 \0 j3 d: M9 _/ J( P } catch (Exception e) {
: p) {9 W6 b- l' y System.out.println("輸入錯誤");( U! m1 d$ o& D* r% l- ?; C2 x' ^
}
: }: {2 ]3 O" n1 l' @. [0 q7 ?
3 j( L5 `; q; L$ k }
4 a8 H8 x# k. D* I
* k/ p/ l. v/ K3 L6 P0 ^} |