加入偶數判斷式~~
* |) a1 q7 D; a3 l+ M* Npublic class TQC207 {
4 K# f; j% \! {7 c9 K; s3 G. j) m) N" c
public static void main(String[] args) {
5 [7 ~5 ]' _3 x3 Q int sum = 0;
6 P- e: Y& m% @) o+ Q# Y; W int odd = 0;6 N ^$ _' n) v* ?" b
int max = 0;
+ |+ m+ N0 k; C6 ~ int tmp = 0;1 f8 T9 C! _6 l/ T# n/ h
int even = 0;
4 h$ k" o E7 Q% r6 X int[] nums = new int[args.length];5 G3 H$ [5 S0 [; h) K9 }9 |
System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
. ^; Y9 R: m8 I try {) X0 L. T: l: V; h1 E1 e
for (int i = 0; i < args.length; i++) {
+ U* L8 o) k# m% J* X8 ]" K- v tmp = Integer.parseInt(args[i]);2 m/ `' y) G' j5 c
nums[i] = tmp;
5 n" d) Z. O8 }* `: V: K sum += tmp;
! ^7 D3 `* J0 D w# P8 j& \ if (tmp % 2 == 0) {
5 j1 q9 Z E# E+ M even++;5 a' _, U5 e* C. z6 F
}# a- T+ ?& N2 P: G' b8 b
if (tmp % 2 != 0) {
; f# K# z3 E: B/ o odd++;
$ w% H0 e6 N) l U, U4 @) I }" q" u$ [' M5 J( M5 h/ z6 _' k
max = Math.max(tmp, max);
r* v6 ^7 L N0 V- A7 ] } m1 H! c6 ]3 i' ?( t
System.out.println("最大值" + max);2 ~/ K/ t$ F% i; j9 U! n
System.out.println("奇數" + odd);8 j1 Z" P4 B3 ^2 a
System.out.println("偶數" + even);
+ _$ C4 V# k0 }7 o System.out.println("總和" + sum);
- j2 C# c+ t2 n/ F5 m, i$ Z' G } catch (Exception e) {
6 s8 m! N9 W6 i. i1 P System.out.println("輸入錯誤");8 B( }0 C% a8 k: j0 e
}% {" ?- w8 b5 k6 V* x
0 q6 T# v3 N% V; _ }
- v' {8 o5 O' s, N: p: h' k7 \
2 {3 L7 a+ v" i} |