加入偶數判斷式~~6 b5 f/ U0 {+ T; j
public class TQC207 {. T# E8 ~" Q0 L7 o
8 m( m/ E& [% W
public static void main(String[] args) {0 j+ c! l- P' ?, q3 G
int sum = 0;
; k. O7 X* T8 z2 c- ]# r int odd = 0;2 ?3 N3 C0 _9 D& q- F
int max = 0;
3 k- U- P0 P8 ]% Z$ w# H int tmp = 0;" n4 G4 ^! p& E8 j# L" X
int even = 0;
1 v$ z' e/ @7 Z' k' B int[] nums = new int[args.length];3 I" m7 l1 c6 P% ~- _6 E. P- S3 L
System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
! V$ G4 a" P+ P: @( c6 _- f try {' r- b) {" i, o( C0 h# C
for (int i = 0; i < args.length; i++) {
" Q& q0 ~: u2 s! I$ w7 B tmp = Integer.parseInt(args[i]);" f2 t$ V9 G8 s% P& ^
nums[i] = tmp;
z6 H. c: Y$ s) G0 ~* j sum += tmp;
' }+ l( B' Y7 c% f0 Z2 c if (tmp % 2 == 0) {( B4 U. j! S$ U1 B& C$ {; X
even++;$ _5 y Q) n! V- Y' [) [
}
( z* B! q! f. S% H if (tmp % 2 != 0) {# e. I2 @, B/ g+ L; r }! z x F
odd++;
; A9 r" Z: c; W( }6 _ }+ z" c8 b/ i# B' e M
max = Math.max(tmp, max);% C' x- O8 ^6 ]" }, o8 @3 J3 S" e1 L
}; ]- }! x. J6 F
System.out.println("最大值" + max);
, s+ @% e8 _9 L) G* h System.out.println("奇數" + odd);, G* j, X7 k8 R. j( X6 U
System.out.println("偶數" + even);
" S) E2 l1 H' t$ F6 O6 J System.out.println("總和" + sum);) K' O& N3 _1 q. _/ J
} catch (Exception e) {+ T) `& ~. \6 O& ]. r* U! {, T
System.out.println("輸入錯誤");( m( g3 |( x& W, @4 |" ~( g% Q
}
2 [) O% V' M' q) U* u
: ~# G" ^1 ~& ?2 @2 \, x. D6 J3 e }
: P7 Z3 w/ g- T+ @4 Q- ?
( ?- M( |5 l6 t$ y% D# m- ?8 Y7 A} |