加入偶數判斷式~~
, q3 U& P) [' Gpublic class TQC207 {% v3 z& y: g. x1 `& Q! j
4 v* z: W$ T+ v5 z' o public static void main(String[] args) {
! m# R h" h0 b4 n int sum = 0;) h( e" O4 M) E
int odd = 0;
0 E4 B9 o9 g* H: q$ P int max = 0;) l5 l \3 _+ N2 i4 W v* W
int tmp = 0;
# V1 K0 N3 D' t+ l5 P0 ~ n9 Z) b- _& J int even = 0;
( E' _& C' E6 Y3 J7 s4 x; { int[] nums = new int[args.length];5 m n2 x) G+ Y& r# \0 }' |0 U9 ?6 ?
System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
( u4 W: P: G/ G) r2 D* A# E5 q* v try {& [' H8 Q" P1 B8 ^6 u7 I
for (int i = 0; i < args.length; i++) {
% Y3 O* [) { ?, u# A0 C) N% s9 u tmp = Integer.parseInt(args[i]);: g* ]# n# P& T% ^
nums[i] = tmp;. O1 R4 c2 k" i6 I
sum += tmp;
0 F# q& J3 n% `: d if (tmp % 2 == 0) {
" }: a2 y2 D1 _4 o even++;
2 e J6 `* g- o* h( w }: I4 H- z; ~0 ^1 ^, u4 {6 z# H+ e
if (tmp % 2 != 0) {
" I0 S& \* ^7 Q) |' k! L odd++;
: T- m* ~% [" e" A+ O8 I | }
2 z* U0 ]. ]) }: F- M max = Math.max(tmp, max);
' N, g; y9 A5 x9 z* X }; y+ {6 Z# V! d
System.out.println("最大值" + max);
) E: z* `5 j! H1 G System.out.println("奇數" + odd);
9 Q5 i3 G6 ^' b7 j# w$ R System.out.println("偶數" + even);; F$ S! W5 r' A# t& ?4 g4 |
System.out.println("總和" + sum);
8 p/ f, `) o$ \* o } catch (Exception e) {% H; B5 I! |' l+ _
System.out.println("輸入錯誤");
8 y. E E4 Z! P4 n |7 w }
6 {9 z+ q e% K* Q3 I* D
, x6 o" q' _/ Z4 i, p, w: e7 w% W }# z* Q( q% L0 R$ Q
0 K+ b- }' u6 p% g) t1 a} |