加入偶數判斷式~~5 Q0 K4 T8 F+ {% o8 Q$ s
public class TQC207 {( ^' k3 c5 [& n+ e. d* q
/ l5 \! s8 a& C/ }) r" x, w7 r public static void main(String[] args) {
1 I v- ?+ b8 d int sum = 0;2 L& ~% j% j: }8 _9 q6 R2 ~
int odd = 0;5 A. R7 S9 o% V3 j+ L. A
int max = 0;
* N0 N1 H; [* a/ w! I' p int tmp = 0;
6 G: {; Z! F0 R- [3 [2 Y# H' X int even = 0;
r1 ~1 R/ Q! W1 q int[] nums = new int[args.length];
7 ~4 @+ e) P/ n; b/ F. S! S3 q System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
' J* {1 D9 N; d, A6 }& [, E5 ] try {3 D9 m; T; A" x5 K/ x; G
for (int i = 0; i < args.length; i++) {! t! X. a% g) H; j B7 M: D' a
tmp = Integer.parseInt(args[i]);
: }* O6 ^8 a2 P2 S nums[i] = tmp;( Y1 D" \: C6 Z i3 u3 }0 Y
sum += tmp;- [7 S/ Y# |: j! t5 M" V
if (tmp % 2 == 0) {
. {( n! M1 T' h8 \! l even++;
1 E5 k! M C6 a& [ }
H z% a4 g9 p if (tmp % 2 != 0) {) N$ i6 A& }- h* j6 V6 g) h$ q
odd++;8 x: |" u7 C: z8 l
}1 o3 Z% M' X0 _2 D
max = Math.max(tmp, max);- B7 [7 N! Q1 w- ]" w; r$ N
}
1 Y6 X- v; @& Q2 x1 i4 C System.out.println("最大值" + max);: z; p; B2 V4 k" S: B. @
System.out.println("奇數" + odd);
6 h. Q6 H, z S: g1 w System.out.println("偶數" + even);# z' v* F7 u: g7 V
System.out.println("總和" + sum);
! g: ~7 @1 \( g# f5 Q( m } catch (Exception e) {1 M- }7 E3 n) ?% E1 T5 W
System.out.println("輸入錯誤");7 G3 F$ f$ R- a% B
}
- ]* D* X! Q# v" f' Z9 B' y- a
' e" G; y2 S0 x4 h7 ~ d2 A }' U& }' z/ \0 _+ Y& u$ G; q6 w; o
! b1 _/ [ q5 q( `8 R) @
} |