加入偶數判斷式~~
6 p+ o7 I8 p# M9 b) r0 { R+ ^/ spublic class TQC207 {) Z* E7 K9 C' ~- s8 f! S8 L) i9 t3 i
' t/ o& [: M3 K/ a% l public static void main(String[] args) {
! p4 i! n4 A/ B2 l7 S int sum = 0;* [8 f/ P( z8 J% D. i5 q
int odd = 0;
$ ^/ J7 ] \1 a8 p% u int max = 0;
" [, i6 d4 n8 B$ d- s% h3 q int tmp = 0;& x* O& p! s& X; g! Y( t: L: ~$ A
int even = 0;
4 J% r# a2 J) K' `* ~& B. a int[] nums = new int[args.length];
3 U' l7 H# v: Z- U8 ]- R: [ System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
0 G- C2 x( C. @* v' l- c try {4 n9 j: U/ h% l7 ]
for (int i = 0; i < args.length; i++) {
" z z' g+ m2 ? tmp = Integer.parseInt(args[i]);8 L5 }4 Z4 N0 x G, l8 l g
nums[i] = tmp;! O( K8 C* E9 O0 M! U) r, \
sum += tmp;
$ R3 V: e1 X: b! q3 ?3 x if (tmp % 2 == 0) {. c, } v2 B5 A$ H y% |, q3 z
even++;4 I/ n% G. C3 W, r& O
}
/ |, l F1 ^; S6 I& [" w ~ if (tmp % 2 != 0) {
2 F7 `- o7 J8 Y. p( y odd++;: @# W U& U, F e% F) p2 }
}/ a# Z6 u( Y, Y' C: i
max = Math.max(tmp, max);0 i% e/ @: z2 u6 i) M. {/ O+ ]
}0 U+ Y. P, M. k5 L, d
System.out.println("最大值" + max);0 f' g) L+ J* b- { J
System.out.println("奇數" + odd);
' o4 R+ k2 v! J- { Q System.out.println("偶數" + even);
0 A: o+ M' n4 o: j3 r( O& ?* e/ R System.out.println("總和" + sum);) s5 }1 g4 c' p- z1 R9 b- ?/ H
} catch (Exception e) {, B* w" P$ F$ Q# O, B9 u5 r. W/ Y
System.out.println("輸入錯誤");
3 g- {: H7 H C }
# [* q$ ^4 O6 e% `+ v5 @7 I& S- d: Q
1 @0 m$ F" B- \5 T, \ }
+ s3 [7 s; j q+ T. ^% u/ L
: d5 _) I! {: m+ |4 k: ^} |