加入偶數判斷式~~
3 m" C7 I0 g' L( p3 b& y+ J6 |public class TQC207 {
* z0 i8 P% e3 \5 C& h4 q9 w3 E9 e( E% g/ z/ k+ y. ]9 d: O7 W# v, C
public static void main(String[] args) {
5 g! d$ H% b2 D0 J int sum = 0;
) @7 k& m' J6 P9 u3 R* l' C( t( y8 M& P int odd = 0;: G+ I( r# u* }( y8 B5 e! X
int max = 0;
7 ^" _- z5 [5 }. u int tmp = 0;" b. P! V& h' B
int even = 0;
4 p9 b D* V, P" }3 [) w1 {5 Z int[] nums = new int[args.length];
9 j& h6 q8 c* V/ { System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");
( {7 O( ?7 u' M+ b( r. V try {
0 |! X/ [- R; Q/ q; l# W% X! t for (int i = 0; i < args.length; i++) {
& r$ ]3 p2 |0 d1 T2 \9 d tmp = Integer.parseInt(args[i]);
# D! b! [2 }% B0 K nums[i] = tmp;4 G- M1 r' ]7 g1 S4 z& b
sum += tmp;" D& t8 s+ T% S. H
if (tmp % 2 == 0) {9 ^0 f% G- g1 [: t2 D3 v' C4 M
even++;+ E* e$ L- c) w: ^4 {3 F4 e
}
6 G# m, o) Z' Y0 X! `: j if (tmp % 2 != 0) {
) X4 G5 G. W6 L& p4 i odd++;2 f) b0 ^6 c! {) h6 R6 P, W
}
$ O; v5 P2 z$ S9 H3 P6 n% d* T max = Math.max(tmp, max);9 y/ g( O: H, ]' l8 X
}' N. x9 ?% v5 A9 |8 t
System.out.println("最大值" + max);
+ h ]- ]0 W. c+ k# {# Y System.out.println("奇數" + odd);
5 T1 f! l+ H- N( y& M; h System.out.println("偶數" + even);
, Y0 y. i: Z/ l) E* C System.out.println("總和" + sum);0 X$ |, l% w' k4 N* O( Z
} catch (Exception e) {9 o5 _& d4 Y" @$ K- R6 L
System.out.println("輸入錯誤");
$ v8 S- Z& }9 o" i }
& W7 t. s/ j0 [& s" K- e4 G4 n' S8 y
}
: F. {- @* f# S* R+ A: a1 |
# F! e9 c$ k5 P5 J} |