加入偶數判斷式~~+ h5 \0 p9 Y7 t) i1 @, Y
public class TQC207 {! [: ^" C7 w6 k
$ f2 a) q3 K i
public static void main(String[] args) {, C: S+ i! I& O$ J# x- t' k
int sum = 0;5 m0 Z/ K1 e( Q7 w/ C
int odd = 0;) M( f( N- q1 Q( i, }
int max = 0;2 e3 {9 G; b! {& A
int tmp = 0;# b( A" U n/ Y6 U2 w# T3 `
int even = 0;
* _5 L' {6 i) V+ f# R: X int[] nums = new int[args.length];
* P% [6 O0 ]' Q/ j( ^: { System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
+ ?5 B; b* t) N4 X try {
( R0 x. c9 h7 W- M, _ for (int i = 0; i < args.length; i++) {
9 ? I5 Y5 a& N, t+ X1 |+ w tmp = Integer.parseInt(args[i]);" j2 s; A% t! ~3 s+ a$ e1 c* y: h
nums[i] = tmp;: X. l! [1 ? J- j/ H
sum += tmp;: o6 F! H/ z( d, R
if (tmp % 2 == 0) {
3 ~; u: Y4 w" ~ c% }, f even++;- S# p- D: f3 ]3 ~2 H# `# s! {5 w
}
0 S+ w }+ O Z; a' J; |6 F if (tmp % 2 != 0) {9 C3 v$ a. b. A) w, O: _) i
odd++;& V" ~& X( x k) M) E" | ]
}
7 C1 [ e. E9 N. M max = Math.max(tmp, max);
6 B1 S0 K2 P/ B0 s8 O! Q4 ] }( @# e/ E) p3 P0 F9 a5 Z
System.out.println("最大值" + max);5 c' r, I! I! m7 {
System.out.println("奇數" + odd);
8 C# L0 M, u# t System.out.println("偶數" + even);" R' n9 k; |3 r) T" R( O& h
System.out.println("總和" + sum);
' x f; ] Q, P9 ^ } catch (Exception e) {3 `' [6 j' W3 A- o' J0 I( Y6 q5 h
System.out.println("輸入錯誤");/ H' A- P, y. p. n
}
" m$ a6 s0 a+ q2 I ]
; H* H2 {" F5 p& t* I }
( q1 r- n4 _9 t- G3 B; Y) v% s* W0 W# M) W4 s2 w0 N/ `1 x% a
} |