加入偶數判斷式~~: ]/ Z+ z- M5 p% v4 _6 v
public class TQC207 {" t; r) p* x& m, F0 X- Q' j) K
& e& _3 @( [6 C7 k2 f6 M public static void main(String[] args) {. `5 y/ o5 ^( {
int sum = 0;
2 c p7 [( j7 T int odd = 0;; R: Q/ z8 z4 a* k1 O j0 ^
int max = 0;! d$ t) F. s9 F6 {& J
int tmp = 0;! Z4 s6 L/ X7 c0 U. ~
int even = 0;+ z. l" i- `- B# e0 B5 V% g
int[] nums = new int[args.length];1 R; f: d! A- ^) }( B7 y# o
System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
3 Q0 ]1 N. E' a7 }; [8 U try {7 f- S; l3 W( { d
for (int i = 0; i < args.length; i++) {
3 a! T" p P" D8 ^0 a" n% p3 @ ~ tmp = Integer.parseInt(args[i]);; P0 A0 x1 @5 h$ X
nums[i] = tmp;! o3 H, K6 X, K- n- `
sum += tmp;
+ G9 I. A! J6 q9 k if (tmp % 2 == 0) {! ]' R. ~, }3 Q( ]+ c9 {% x# J7 _
even++;/ C# r4 }9 P7 } q' d" K3 @
}
, D# V! |: `8 r. W" i \ if (tmp % 2 != 0) {/ F5 {. I% a' Y5 x1 B, V2 w
odd++;5 e. m: o( f: Z0 J3 ^
}
% q0 ?# c4 C+ ^- k( t0 D7 t max = Math.max(tmp, max);
: x5 ^: R2 j* K }
& h f% o3 _" E, @ C System.out.println("最大值" + max);4 j: }7 [0 n9 B6 _" \0 Y$ |/ s
System.out.println("奇數" + odd);6 {' e' m5 \ d9 V
System.out.println("偶數" + even);
1 w+ \7 T E+ B, w( I$ t System.out.println("總和" + sum);/ u% [- P, m) _
} catch (Exception e) {, \+ d( U( n9 c8 h( t. o
System.out.println("輸入錯誤");, W# o% b/ Q8 H! J$ E* H4 r0 ` R
}
$ ?" r7 V x3 J4 \& @) _6 D8 o4 d, i
R3 f9 A* G, ` }
8 q, b' t. ~% L* W7 J) T8 s
' P6 ^% A& Y/ M} |