加入偶數判斷式~~; p9 G# y6 s3 ~% c4 f
public class TQC207 {
0 H" S% ]9 ]7 _. a$ S% W6 @) d" d% x- Z, {
public static void main(String[] args) {
# d5 u1 |. ^0 d& q, d int sum = 0;+ V6 q* J3 C+ C5 t
int odd = 0;" a# ]7 L$ \. J5 e y
int max = 0;: v/ Q; p+ |# @! b2 s
int tmp = 0;: E- ]. G+ K! d
int even = 0;
4 N0 [# Q9 L. J* g1 H+ k% s9 s( w int[] nums = new int[args.length];& C& V# _' ^! A) P% C- T( W
System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
" y; E' u i4 r1 U9 _- R try {8 c6 K1 K8 l r: `3 c6 b
for (int i = 0; i < args.length; i++) {6 K# D* a0 p4 ?$ {
tmp = Integer.parseInt(args[i]);
7 M. `) D% e6 n s! y nums[i] = tmp;
. w% _6 |" P/ x0 M7 z sum += tmp;
. }" V0 T' ` ~ if (tmp % 2 == 0) {
% c4 G! {" ^6 `. q6 Y even++;# T5 h# K0 H& i& `
}
5 J6 y" N0 R# F if (tmp % 2 != 0) {
8 O# P! q6 U4 m# ~ odd++;
) @% z5 W% s2 h }
& {1 d0 ~& m Z* p max = Math.max(tmp, max);. _2 P, R& c- j. t Q! y
}
7 ]: E& c: H! y" v! r System.out.println("最大值" + max);; b5 W; F* S% @& W# s- Q4 @ e" ]) n9 v
System.out.println("奇數" + odd);5 \0 s* x7 r$ o
System.out.println("偶數" + even);
8 `3 u* Y* ]5 J$ O8 [ System.out.println("總和" + sum);
# c# o& T" ?# K9 V' ^ } catch (Exception e) {
% ?$ O* v& w3 R v$ e/ N System.out.println("輸入錯誤");2 g9 R3 i7 c/ ~ j" I
}3 J8 w3 @8 V, `: L3 L+ N( | o* d
) P0 _9 _- B/ T1 F7 v" ^
}* H3 K4 ]" v' b6 B# L0 h4 q
0 V! Q! N7 A" }} |