加入偶數判斷式~~
8 K Z4 B$ s @# d3 fpublic class TQC207 {( P" O1 D8 D, A5 E1 }! Q1 K
- f' x% \& S2 r$ _ public static void main(String[] args) {
' p* I; K) p0 _& s+ d9 b int sum = 0;
/ P) W% x; s2 L2 d. J* S7 \ int odd = 0;8 x1 J8 o% b% r$ Z
int max = 0;
d9 M3 b) d- r+ e6 _ int tmp = 0;
$ M& R, f5 L' L int even = 0;
" q" j4 `0 @8 c! D- u int[] nums = new int[args.length];
9 a8 `4 i4 u1 n# N- S System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");6 T1 H# ^5 j% w2 f# V" r8 N% n
try {7 ]& X) u( K& V
for (int i = 0; i < args.length; i++) {
- l9 m7 M% ]6 O+ | tmp = Integer.parseInt(args[i]);
4 w$ k/ ^/ O, I nums[i] = tmp;
/ G% g" n2 _' K1 g8 [ sum += tmp;
- M$ ?& [: I$ o$ c' [0 `- z if (tmp % 2 == 0) {" b- n% C) a( P- q2 |) r6 B+ w
even++;
7 E" l5 B- j+ w/ J6 A- G4 z2 p3 ? }
, f) L2 C" ]* A2 B, v. r if (tmp % 2 != 0) {+ W, d" Q- k7 T- h9 c/ ]
odd++;$ O+ O! b: |0 Y
}
/ T- v4 a8 U5 D5 r max = Math.max(tmp, max);
0 M& H; ?. R, C1 Z }& F; R+ x6 Y' z- G f( K7 R
System.out.println("最大值" + max);
/ b& |! F, {2 [* |* v# O q System.out.println("奇數" + odd);* L9 H; s f7 n5 x+ U9 t5 P
System.out.println("偶數" + even);, A- m3 x& H9 b+ S
System.out.println("總和" + sum);
8 W; f6 f) X' a. G. g: Z5 y- d } catch (Exception e) {
2 g+ x7 [" b/ N4 i System.out.println("輸入錯誤");
# X3 f. G2 b& F5 ]+ z; Y }
( J6 ]6 g4 H- s/ _0 U3 Y" n( j
}
& Y/ ]. W3 Z$ O3 Y( K6 z* D
8 ~; j" C4 k9 ?} |