加入偶數判斷式~~
7 ]$ f8 Y$ x( C4 Y$ ypublic class TQC207 {
9 Y4 m5 E6 J9 p% t0 F* B; r: m! ~, }5 I
public static void main(String[] args) {$ z& {& w3 M8 p+ x9 G7 u6 g+ i. f
int sum = 0; s, z9 h4 \8 A( G7 |7 y h
int odd = 0;: ]; O' Q& Q8 t
int max = 0;7 Q6 a8 B/ s- P5 U* f1 M. a
int tmp = 0;
. W+ A2 A% J' v2 o int even = 0;
7 E9 o0 Z- x; ?* k int[] nums = new int[args.length];
( ]1 m1 _1 V$ {' L+ c1 i: x2 S# I# b System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");, z& \3 ?: W( b
try {
4 Y1 u" D. P7 l7 \2 G, | for (int i = 0; i < args.length; i++) {
' O- ~( w5 z, \7 v9 k tmp = Integer.parseInt(args[i]);/ h/ ~1 a& O# V! n
nums[i] = tmp;& ?! w! H) a* b5 S) A0 l9 J: Z! W$ u
sum += tmp;' E. S1 ~) ]. b
if (tmp % 2 == 0) {
U2 f% q+ H8 r$ N' Z4 r5 i even++;
* `+ `- e1 H+ y4 G }$ ^0 @) p+ B, M/ O1 `& _3 S
if (tmp % 2 != 0) {
J3 w2 j! w6 Z9 M2 N. S- j odd++;8 h1 |7 M5 [$ f/ e
}
+ f1 h/ M" L9 m max = Math.max(tmp, max); v. E; J A* ]" T, @3 M
}
* i, \# v$ | B6 y5 N2 A4 z$ ~/ J System.out.println("最大值" + max);0 x- J9 T/ O' D; Y- Q1 L
System.out.println("奇數" + odd);
) w* f3 t: n: p0 v P3 U7 N$ } System.out.println("偶數" + even);
, ]1 y" H. p2 a f5 @! s/ u System.out.println("總和" + sum);
9 ]% t) d, d: ^. @ } catch (Exception e) {: t' _9 N& V3 w+ u% B( R
System.out.println("輸入錯誤");
4 z% o7 ~# g4 i B4 H }
& ^9 O3 ~& Z& T* m9 p' h: P( H: @) B3 K) K- q( k! `
}
/ ]: i) [6 \; K! ?0 F6 W: F4 g2 @6 U5 S8 R/ L9 l
} |