加入偶數判斷式~~; H F* o! T/ k- Z' y
public class TQC207 {
8 r3 {% w9 P' M5 f) M; }) n' y; {5 ?; f
public static void main(String[] args) {
! x" X" J( b& N1 t2 m8 l, s int sum = 0;$ a2 Q1 n' S- e4 a+ p2 b
int odd = 0;) ]. R9 G9 T1 |& E- d( b0 L
int max = 0;
' E& g1 {; F f( _$ _: z6 H int tmp = 0;+ L4 O2 Y6 j6 d6 i0 G) x
int even = 0;" v! u5 @+ K. ^+ f
int[] nums = new int[args.length];$ |% V+ E% u% l
System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");# B: H4 }/ ^. }' }% G+ c5 k
try {# B" y" E. a7 H- p( @
for (int i = 0; i < args.length; i++) {
3 Q' d0 t% z* k4 H$ }' } tmp = Integer.parseInt(args[i]);
6 Y2 q" z8 G4 q1 C4 `3 R, z3 W nums[i] = tmp;9 z. a4 E7 b' ~+ n0 E
sum += tmp;2 d1 u6 v6 l% ~8 q
if (tmp % 2 == 0) {4 U) {) K5 ~- ~7 ]
even++;
/ f; A4 B5 H* E# b. P- n' h }
( p& R$ v8 ?) P o if (tmp % 2 != 0) {
9 s, ^: B2 g0 x3 }* R$ O odd++;
) V$ i5 ~& G6 B }7 X5 R$ T- _4 O+ `5 r- I
max = Math.max(tmp, max);
0 C3 R4 _* k3 S* M. H, Z, U6 B6 Z }
5 W0 `' G- ?. q& s- P& ]9 R$ M# [ System.out.println("最大值" + max);
, z# ?' j- e( f1 A System.out.println("奇數" + odd);
4 x; T3 W( S S% O @ System.out.println("偶數" + even);
$ T# h5 D8 a4 ^. ^6 z System.out.println("總和" + sum);5 t' J; U2 l+ r- G8 q9 U% n" u6 l
} catch (Exception e) {2 Z3 g4 U7 D# w6 P& u% j
System.out.println("輸入錯誤");
6 H/ P) W# ]6 c7 }+ b% h3 t }
+ I; j5 l, ]8 p3 _/ K5 U0 p; E- p' K' T2 E
}6 u2 R) W) V/ E5 ~4 q: j+ U
* j, B' c2 D! a6 e
} |