加入偶數判斷式~~
! D r [: Y. [public class TQC207 {
" K; k7 \) V4 X4 i* j1 g G; F, \
public static void main(String[] args) {
+ Y4 h. e- n% C- l8 W. n' y int sum = 0;+ v5 @6 r/ [" ]. R9 l- |
int odd = 0;1 W7 u4 g4 R0 L
int max = 0;
' C' f' P9 l) v* @' q% n int tmp = 0;6 B- \5 {/ |+ s' e3 R3 z
int even = 0;
H9 |/ @: A" H2 C/ G1 _. Y int[] nums = new int[args.length];
& n2 E4 j$ J% k System.out.println("請輸入需要判斷的數: (數字間須留空白!!)");* O3 d9 p3 y7 d& u+ t& V" Y
try {
' l# \3 h7 Z' l9 N9 C8 Z: x for (int i = 0; i < args.length; i++) {
) G+ |- E3 M' u- S tmp = Integer.parseInt(args[i]);
+ N+ B- Y/ Q" W3 C4 X( [4 K nums[i] = tmp;4 {; F N) M& S& `4 z4 O
sum += tmp;
+ t. g% p* P: A if (tmp % 2 == 0) {0 \ l" L6 @- z" Q0 ]2 b
even++;7 j! h9 r ?5 e# G _' f
}2 W- G; `) E/ d4 a9 w0 y/ y$ u
if (tmp % 2 != 0) {7 J' l/ N9 y x, d( a' s* k, ~
odd++;: T; d5 C. `. V7 r" H
}7 ]4 K1 }1 G/ W2 H( ] ]7 n/ A! F
max = Math.max(tmp, max);
/ ^0 W) }0 S- ~5 b1 B9 `2 x& |" D }
J7 d" |1 A6 o6 b, Y System.out.println("最大值" + max);
4 H7 g7 H7 R$ e& [1 D2 D% t System.out.println("奇數" + odd);- O/ W) p1 D: G4 u1 e
System.out.println("偶數" + even);& L) q" H6 q, c2 b# @) I
System.out.println("總和" + sum);
! i$ R: ]/ P! K( J! Z } catch (Exception e) {
8 J( g1 Q7 b6 B. o8 P, O/ i0 K7 s System.out.println("輸入錯誤");
( c: E* h2 x$ L# t! w5 v& d% } }" ^& J( Z0 R$ y, e
% ]% b$ \) T8 x* K2 v) P
}' E& T! H! W8 C* B* N/ b9 I
/ h5 B# }! ]# s" e; y
} |