加入偶數判斷式~~3 u. [6 `" Y$ ~* |/ e
public class TQC207 {- w. s, r5 Z) K6 U: j1 U) V2 a
& c# Q! b' u7 d4 v: v
public static void main(String[] args) {! @7 {4 |& U& j2 Q; G2 R" f
int sum = 0;5 M5 s; Y$ _) Y4 _3 j6 F2 P% Y
int odd = 0;
3 F7 \8 s! Q/ G$ f- Y int max = 0;! X: q0 ^4 P! L0 O* Q' A6 ?3 e% h
int tmp = 0;
# G, I' L9 k0 S$ C$ h& w% S int even = 0;9 Y8 d4 K( z( p0 q
int[] nums = new int[args.length];
& M. X, g7 _6 a System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");; h5 N1 I: D, Q& h) K+ E. L4 N; n
try {
: I' D% Y3 |- s( a for (int i = 0; i < args.length; i++) {
- S- G: s+ b, T tmp = Integer.parseInt(args[i]);: @0 F* Q/ n5 c
nums[i] = tmp;( v, l$ q" _$ R. W) W
sum += tmp;
o6 l+ E* f, f if (tmp % 2 == 0) {# T% O/ {, g' ?( r2 R% f) m
even++;0 i4 q9 n* c) p2 x; g8 t
} ^# A% }* l$ O
if (tmp % 2 != 0) {6 A8 Y* A: x% n" a1 H
odd++;
& C% }6 @+ T! t0 W. t }- p. b& S1 h( ~
max = Math.max(tmp, max);9 B4 [! l2 w* P$ X" r/ j6 v
}
# K1 @8 W* a! l1 _ System.out.println("最大值" + max);2 l$ K. ^- \- v% V2 W" s% r
System.out.println("奇數" + odd);8 A3 l* @ }5 T4 g1 o
System.out.println("偶數" + even);) L r* ^- S0 m* k* q/ [
System.out.println("總和" + sum);
" T/ _: X2 P1 b( Y7 ~ q& I } catch (Exception e) {
( s8 E- A% s6 B% g# o. l7 | System.out.println("輸入錯誤");
$ P/ L6 p. f ]# n } Y0 ^ B' U: e+ H- K6 o" D
D) _6 I& ~" D9 p( o
}
: I. O. w* T( l3 E& ]4 o3 B- K% R. y1 m
} |