加入偶數判斷式~~
9 B! Y+ E, n0 F# Cpublic class TQC207 {1 |9 j c% h+ x6 b) r7 E' ]- |8 G
9 E1 r( @" }9 q+ G! o! Y
public static void main(String[] args) {
7 ]' {% P C7 z# q2 e1 _$ D0 t% n int sum = 0;
+ p! T- B) O& x8 [ int odd = 0;1 `# e+ C, Q; o! K8 A$ J
int max = 0;" Y- _( B. G/ C r3 Z
int tmp = 0;9 ~/ }% a. S0 t# W, r
int even = 0;
3 e/ a8 v3 n$ }; K! C! I int[] nums = new int[args.length];
% D" \ |/ P: E# P+ _, W5 V% X System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
* k3 _" V! V, s5 z. @7 s try {8 Z, E/ E; v; O0 k# n% x
for (int i = 0; i < args.length; i++) {
+ B4 B( E: O( Q tmp = Integer.parseInt(args[i]);
@ a( y# e( m) _$ e8 a nums[i] = tmp;
4 b: G7 _; ~! y$ a# J sum += tmp;0 W6 i' K* q, J8 a3 {. I) @
if (tmp % 2 == 0) {
: N) u; W$ g/ ]$ w2 ^1 l even++;
; c4 t; f7 ~1 ~7 L }
. e7 Z7 m4 L5 A if (tmp % 2 != 0) {; P& W5 ], z5 `4 }7 s: z4 U# v
odd++;: G3 _+ T" i0 F' m% n
}! ^0 w/ s/ ]/ y9 d0 n. v r2 E
max = Math.max(tmp, max);
! o$ K9 ^% u3 t+ G }7 u( n' m) i0 _0 n4 m
System.out.println("最大值" + max);
% h/ H" t" W& [/ {1 m1 p System.out.println("奇數" + odd);1 Y) n; m2 J. B% {2 U6 T! p8 n
System.out.println("偶數" + even);& A- o) a. Z( Q1 R" l5 u: c7 q) |
System.out.println("總和" + sum);
% T+ E: }5 D, D" b2 j7 x } catch (Exception e) {) j) a7 A P! [ ]
System.out.println("輸入錯誤");) |" }! K% E: s8 y
}$ i- m1 f0 V3 Y7 |
' V3 i1 |. X: ?" b) K [' U% _
}" S5 P9 r+ F' x+ N) u+ J& S
* n7 U* w7 }) m) d
} |