加入偶數判斷式~~/ v z4 F/ m( t3 u, v7 B
public class TQC207 {: b# m! W0 o& }
$ W0 \% _3 \0 W |8 o& S, d
public static void main(String[] args) {& y( w& p" H1 Z- J; q. K7 `4 N/ ^
int sum = 0;
) g, y: p+ c# R7 p. u. [ int odd = 0;. {# J! s/ Q3 t* f% ?4 K. |
int max = 0;/ y( u% |. M# F! U4 n0 i& o
int tmp = 0;
. f: u* [+ m2 w( R7 d' i int even = 0;
+ i4 I1 O/ @6 w6 ?9 ]6 r3 L int[] nums = new int[args.length];
6 l. R$ ~, p5 \. O System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");* d* R" }) ^& z0 S
try {
6 H. s+ ?) u6 y for (int i = 0; i < args.length; i++) {& p2 o! _2 ?3 n3 T( C8 B6 r
tmp = Integer.parseInt(args[i]);4 O0 {7 ?2 f! y6 a
nums[i] = tmp;
1 W' u* k T+ b) c sum += tmp;, Y& k+ ~& q4 I1 U! L2 p
if (tmp % 2 == 0) {
. @/ f% L- ~! m# V: D2 M4 K+ D even++;
) P" @5 v/ S0 e }* B% N3 c" `' x& ^( |# w
if (tmp % 2 != 0) {$ \. E) p2 h/ s' _, |1 U% h
odd++;
% _: a3 u( a$ p' F7 @ }
9 m" n% `8 `5 N0 u% o6 ? max = Math.max(tmp, max);
2 |% s5 x) A3 S) m0 \0 w, v* y }, K% I: x0 H. H% G0 T0 A
System.out.println("最大值" + max);6 z+ J' j' m- f7 f
System.out.println("奇數" + odd);
2 r7 U6 i+ c+ V0 h; v3 B; { System.out.println("偶數" + even);
0 J7 ^ ^% X: k* Z System.out.println("總和" + sum);6 l* x6 g4 _7 R7 m: ~, Q R
} catch (Exception e) {( }5 i8 S0 G1 a& ^$ ~8 B
System.out.println("輸入錯誤");
, ]1 b- `; \4 ]4 Z: H# [7 [4 } }( \6 k" H& w% g6 x6 ~" `, }
" `$ U2 n; o8 v, X8 w
}- ^. y5 ?% z% _
8 Q. F8 ?5 \* @- t- R. A2 d: i4 K; @
} |