加入偶數判斷式~~
6 q; R9 I6 W6 h3 mpublic class TQC207 {' [6 N1 Q( S6 W# J
9 e% k2 D, L# G0 W7 [) g d
public static void main(String[] args) {
( F6 K) Q- Z. H- b, \* m2 A! v/ M, S int sum = 0;8 y% D0 C3 W3 l0 G9 ^/ O
int odd = 0;( O% `0 G k3 U- f: _
int max = 0;
+ r8 V9 M& c0 ` int tmp = 0;
0 f: J5 _; H5 e+ E) | int even = 0;
! O2 k y( o }; N) o* J: W! a int[] nums = new int[args.length];
3 _- `" j Q9 B$ e System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
" ?: G* a% q; h( u' U# } try {+ Y* E% k9 x% o0 r& @
for (int i = 0; i < args.length; i++) {
. y4 V* {$ ]9 C$ e3 w% a tmp = Integer.parseInt(args[i]);
( e j, Z& x! }7 h: ~. ^ nums[i] = tmp;9 a3 Q; L# p- H1 ]3 A% G
sum += tmp;
0 z7 X" R& a/ ] ^/ Q if (tmp % 2 == 0) {* w5 R, ^, l- F: }+ J* {. t+ ^: |
even++;# g. A1 l0 \5 _3 {) R2 L- I8 v2 n
}7 j5 j% k- o7 E- v& J0 f7 P
if (tmp % 2 != 0) {" Y: D( ^( v. t8 N6 a
odd++;. b" j, q6 v* \3 y6 X! Y
}
$ \& {. K- t, F2 @ max = Math.max(tmp, max);6 U2 ? g2 r5 p) Y
}5 y) Z' s; F" @$ [
System.out.println("最大值" + max);
6 f% \" N9 {. u' c& O: _# C& S System.out.println("奇數" + odd);
' F# R3 z% F# q( }" L& G. f( c2 J System.out.println("偶數" + even);1 @4 L& h1 m# X* c' z& P B( R
System.out.println("總和" + sum);
7 @% n/ b; l) K+ R } catch (Exception e) {" t" H% ~* V( y% q. a
System.out.println("輸入錯誤");9 J }6 S- B/ W9 W0 ^ b8 i/ [
}& e. j2 r% V7 Q! i
5 M" N: d/ b6 ]
}8 d( j4 {. e, G* f5 x* [% [ h5 c# e
, `' b# }+ k) N+ v
} |