加入偶數判斷式~~& `1 T" J$ Z% W9 y
public class TQC207 {
% p6 [ f6 Q+ R K9 l2 ^4 d7 }% J3 Q) k; l8 ]
public static void main(String[] args) {
0 @, T) Y% {5 @$ I( M int sum = 0;+ s- R- v2 V- ^5 s/ f$ P% V+ U
int odd = 0;
+ F" P- G w' K, ?3 O$ B int max = 0;% F4 @( ?( Q6 r% h: `/ K1 O
int tmp = 0;( u4 J8 h: \" a) b) u
int even = 0;
7 X+ s; J; O" F$ f8 G. ]3 N5 l3 } int[] nums = new int[args.length];
3 K! H$ w0 }1 ~ System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");5 p e+ l! @0 B
try {
7 o1 ^. |0 m+ m for (int i = 0; i < args.length; i++) {, u3 U" F" b" O" O) }
tmp = Integer.parseInt(args[i]);
$ L0 s; e2 z8 [5 g( P nums[i] = tmp;
+ y$ O P5 I4 @4 q1 r sum += tmp;
6 c' F( K0 B% k/ a% r; T if (tmp % 2 == 0) {) i8 l+ J7 p9 ^
even++;$ X' m& w! G3 G4 l5 L& b
} |9 ?/ g) e! b4 t
if (tmp % 2 != 0) {
2 j" K) L. |2 U; h$ [% F+ X8 v odd++;+ b0 P8 n4 q x
}; R1 h9 ~9 v. O
max = Math.max(tmp, max);8 q7 X, }. |5 d( {7 g1 b, Y
}! l% D& A% k( U
System.out.println("最大值" + max);1 W/ @/ d1 q7 V" G
System.out.println("奇數" + odd);
: v. h' t! R c. w/ h& B- j4 T" i System.out.println("偶數" + even);
, t+ |7 h" W! D" M1 s System.out.println("總和" + sum);2 E( P4 q8 b z0 b6 z. O3 d$ v
} catch (Exception e) {7 U# Y- `7 ?. i8 R* K6 i
System.out.println("輸入錯誤");$ V; |# V9 V3 y4 V8 b" s' p
}
$ F1 h! }' b" l* p) N% v( D, B. j# h# ^3 U! F
}" p9 `7 I/ s1 e7 Z8 R2 p
, `2 H& Y. K2 W$ A/ O0 E+ X" [+ _' v
} |