加入偶數判斷式~~
+ v- o D3 v" I& a$ tpublic class TQC207 {3 Y% K4 l1 H ~. E; R. z
% {( h: M& J+ P+ Q public static void main(String[] args) {
. `+ q7 r( |" E& W int sum = 0; W f, T( D3 Y
int odd = 0;+ V0 l2 U8 U5 @8 `+ D1 U6 N
int max = 0;4 V9 [% Q9 Z( Q6 u* h \% |
int tmp = 0;
% D, }/ M' A2 \) G' y; Z1 h int even = 0;
& `% N- u0 v# G+ }' ^- ? int[] nums = new int[args.length];, d6 A/ r5 Z# R7 T% e8 o, B& v7 b: @
System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
1 e, q, E" q3 w9 D try {8 U& r7 F2 `5 q% [: i# y* k
for (int i = 0; i < args.length; i++) {
. ]: P# x$ S/ G$ Z4 K- y tmp = Integer.parseInt(args[i]);# Q5 }" @9 [7 o- C# q+ U7 o
nums[i] = tmp;
; {5 A. R% b r3 p sum += tmp;' |8 A0 K( P# g) x
if (tmp % 2 == 0) {$ I7 |$ s: g8 X' G' b0 Y
even++;
b2 \+ |" k" q* Y( ] }
) m' H* X1 T j3 P2 e if (tmp % 2 != 0) {+ ?# G$ A5 A5 Z+ L
odd++;
( B9 x+ G9 p1 { x( Q }
A( D; j! m3 g# s3 j max = Math.max(tmp, max);- m8 @( B( s8 C8 x6 V
}$ J( I D5 ~" ?- M
System.out.println("最大值" + max); e" l0 }" p# {
System.out.println("奇數" + odd);
/ j! N# _5 X$ t' C1 B$ q& ~ System.out.println("偶數" + even);
3 [) b, q; N) p System.out.println("總和" + sum);! U4 x) Z/ J- i8 U& A+ Z) x. m
} catch (Exception e) {1 e3 }' y8 j& _$ K& l9 u8 W
System.out.println("輸入錯誤");" n/ p/ N" |" d2 v* H3 T
}
* }' S9 ^- r/ L4 t2 r7 @
$ u% m& n% @ q3 b) c( p- M5 R }
; T2 p. x, D! G: b0 U
0 M) T5 P) h3 t5 E, o} |