加入偶數判斷式~~+ o! y( m" P5 U$ o$ Z
public class TQC207 {
9 N+ F: V: Q8 l: j2 u6 q8 ?
. U% z2 n2 \; S public static void main(String[] args) {7 d# ~8 |( `0 T' p4 P- k6 `
int sum = 0;6 X4 C9 F$ [& b
int odd = 0;
$ X/ |+ }/ v9 s( B1 E2 n) X int max = 0;
$ r, ]! J( ]9 G$ N5 M, z int tmp = 0;
% P* x( O& y3 H8 h/ u int even = 0;
: k- Y0 W2 e j$ M0 E1 S- {4 i' x int[] nums = new int[args.length];
; x; K3 D5 j2 B2 F( P1 g9 [) p System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
: V( i' W# c9 V; W6 A5 S try {
* \( G6 z! c R$ [( I for (int i = 0; i < args.length; i++) {0 S0 ?9 p' j( M" ^0 w2 k/ n
tmp = Integer.parseInt(args[i]);1 w; L# P \2 v
nums[i] = tmp;
* d: ^& j' _ L: b5 W4 i- x) ~- R sum += tmp;
# \; K5 E. M* m" L if (tmp % 2 == 0) {+ I1 S3 e8 u" @ x$ L+ i$ h
even++;
% {% H! ?( V) p4 s4 f8 a% a5 w2 k }) O) Y1 y- D) k: E# P
if (tmp % 2 != 0) {, i% l$ \" K/ l# P; \
odd++;5 @0 Q N, I) h
}
. h( ^5 _8 I0 J" d& H$ [% j7 K0 } max = Math.max(tmp, max);% u! ^+ S" c. c
}& e/ U; V& r- u. }5 F: I2 H+ D
System.out.println("最大值" + max);# M, r3 v: P5 x, U( E8 l
System.out.println("奇數" + odd);
: \: m" s- i* q! w5 @2 a: y' X System.out.println("偶數" + even);; \' W( y, Y0 E& c* }
System.out.println("總和" + sum);
0 ~% W, x( w2 h! |( Q- U4 G/ s } catch (Exception e) {$ A) M$ e4 X2 e/ q7 Z9 Z3 h
System.out.println("輸入錯誤");4 R, q" N' j- G5 C3 k
}/ y8 R. U! w! V9 r6 k) G3 s6 b- H
8 x5 f3 |2 |' T7 V+ L }
% ^3 v( M& v/ {- h+ m% D7 Z0 D Z0 G+ O& S! E1 ^
} |