加入偶數判斷式~~1 k8 ^8 j2 M9 r8 u
public class TQC207 {/ J7 e- j4 a0 a9 K, m) ]
! R# U5 e+ N7 q+ a: T# e1 S5 ]' m
public static void main(String[] args) {
3 k, `# ?/ r% K) C) j8 [, S int sum = 0;) T6 R& W* n5 }4 ?: [
int odd = 0;3 k* Q7 a, A) o
int max = 0;3 K/ t. h: T1 U6 B, i
int tmp = 0;
0 E' Y1 W+ M9 a: j int even = 0;4 ^' u U+ W, p2 j8 P+ A7 Z4 F
int[] nums = new int[args.length];5 J/ Y$ {% w q# l C6 H0 j& b& G' H
System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
% g5 X* }& e* P7 b try {" W; }& d* w! n+ L4 ^
for (int i = 0; i < args.length; i++) {
2 j& Q1 K! ?- y# }+ l1 s tmp = Integer.parseInt(args[i]);
- a0 L3 j0 e5 m/ i, j& k nums[i] = tmp;
0 @ D8 g; `2 o sum += tmp;/ w. l8 E0 N/ K2 H" ^& q$ @
if (tmp % 2 == 0) {
3 G M# \; o4 n- q# u& P! T even++;
+ ^/ r7 T' L; O0 l9 x( V. P8 T- ^ }
8 x3 X m) }# [; S4 ]1 w if (tmp % 2 != 0) {
- r5 S9 y4 E' R6 Q+ P: D odd++;
n7 W0 X) U9 G }
0 O% _ K4 s+ p8 z max = Math.max(tmp, max);
4 Y, w4 \1 o' ]/ F/ H; ] }
0 e* f% C" [" P& O; g3 Y; E. h8 A System.out.println("最大值" + max);# V* W# n1 y8 q- y2 ?
System.out.println("奇數" + odd);' m; N" b1 s$ t' M
System.out.println("偶數" + even);
4 _* p" m5 C7 y+ Q P+ n3 a System.out.println("總和" + sum);
3 \4 k2 g6 Z! D$ m9 f5 @ } catch (Exception e) {; ^5 B% ?/ t* x6 R" P
System.out.println("輸入錯誤");' { k" _) i1 V! ~9 n+ ^
}
0 m+ C8 _1 q' l3 l1 c/ a0 b( ]9 G2 p5 k3 d5 e* L
}/ G2 s5 m% H+ D! J
( I6 y" q9 ^8 c- W9 H/ @! p
} |