TQC1071 t2 I: h4 m: |/ u
public class test{& C+ L8 g! d* b( m. j. ^2 ?$ K k
9 v' y$ Z7 F9 u5 U( L1 }7 ~ public static void main(String args[]){
; l1 E+ U. ~( E& v* F& G
* Q! O) u# N$ x. M0 S' h0 e( x: c //0 1 2 3 % ^! j1 Z. \) K; e
//1 1 2 3- t& [" p, I5 u
//2 1 2 3
% Z" o% m, ?9 e! \% F $ U9 @ s1 }8 k, z! \
float tot = 0 ;9 `( {0 s# c* i; l8 x
for(int i=1;i<args.length;i++){6 ]- q3 n" D- R0 A; G" P
tot += Float.parseFloat(args[i]);
/ s* \# I) o5 W6 t6 D* ]- z }
! g6 v2 M4 P5 N& C) Q" a1 ^" o0 _. E tot /= (args.length-1) ;" ?# w; L2 O* G4 B p5 O7 Q
7 S7 j' ]6 X# W; N" t9 V
if(args[0].equals("0")){! d% _6 @7 Q2 I1 s1 a- T* a8 _3 }
System.out.printf("平均值:%f",tot);
* x2 }: ~6 u4 I3 n# k; l }else if(args[0].equals("1")){
0 [) K8 S9 F$ j. e3 O- g System.out.printf("平均值:%.1f",tot);" m7 h, r* ]3 E) e, t7 O! C9 R$ H
}else{
& W. H: J) f/ n) o. D- J& v System.out.printf("平均值:%.2f",tot);
! E, k4 f r: d }
% v: s3 R! T/ z4 ]
6 @: L5 d/ {( g- u. J% x
/ H2 t0 U& o6 Q9 G* L* |! O) d3 N }1 o" m& K* w) [7 ?: F
& y( U* L& k2 r" q( G: N8 Y a7 Z: |! i6 M) Z6 z( f& M
}
* p5 S; ^8 L' e- RTQC108
0 K" j; F' U2 R5 J0 Q; R& Simport java.lang.*;4 Y/ {( X( X. I/ B. t6 u* K( Z
; l$ a9 E* Z& S J3 ]) l
public class TQC108. G9 M# e! J" i n2 g# y: G
{
! |/ u. T4 `3 Q" B# P public static void main(String[] args) 8 H, p: R- ?0 o' L. _
{% s3 c9 h5 V5 r8 {3 }5 T2 l f
for(int i = 1 ; i< 10 ; i++){
8 G7 G/ D( N+ l, ^ for(int j = 1 ; j <10 ; j++)
6 Q' U8 D* I6 D System.out.print(""+i+"*"+j+"="+(i*j)+"\t");( O; `+ R: n- \2 _) n/ Z
System.out.println();6 n3 H2 K4 x9 L. A2 ^& g
}0 Q& _( p0 x1 e3 n4 b: b
}, E y) i1 F3 X2 r1 ]6 B7 g6 O
}6 P; Y/ `4 o2 ~
4 l$ a) m n! f5 a# d# H
8 J' U1 k# S4 l T# |* j0 RTQC109
; D, |# X* t# l7 L/ _. Wpublic class TQC109 {1 e% }" m# O; {
public static void main(String args[]) {+ b9 j3 J) u. r
int r;, }% @7 O; z6 S2 W
r=(int)(Math.random()*100+1); z0 X8 S+ E* D( p" }: ^
double area = r*r*Math.PI;
0 Y$ z) {" q7 i. f2 F double vol = r*r*r*Math.PI*43;
! M }5 J# }. n! m! T System.out.println( "隨機產生的半徑為:" + r );
3 H% m2 T- K# |# \ System.out.println( "計算後,直徑為:" + (2*r) );7 `9 E+ o! l: t) `5 [) {* f
System.out.println( "計算後,圓面積為:" + area );$ u4 u8 o/ Y9 ~" H8 [# l2 ]
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);1 r: T/ X' h# v/ Y. b% j9 n
System.out.println( "計算後,圓體積為:" + vol );
. U5 }2 f/ n$ [, i) x5 p* ~ System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);! B1 b8 _$ y# N8 v
}4 @1 v, w3 j6 y+ p; i
}2 v, S$ t: y& h/ F5 w6 p1 d
8 H; x& I' H- S
- W1 B/ w5 s4 c- V, [0 G
TQC110 7 @+ d0 }+ r/ e/ F* G
import java.io.*;# r% r: ^5 D8 {3 T' [0 H8 I
import java.util.Date;- p6 n. ]' u* Y1 I* t+ V
+ H2 y$ ~! e# B( {) V+ d
class TQC110{' A. z' N9 H) y* w9 o! ^
String items[][];
: g& f8 q. ~% D long start, end;* h9 `9 G( O8 @- q
Date d;
6 K: Y: \ I% i+ w, X _7 n o BufferedReader br;+ s4 t- m R: F1 C' e7 E) ]5 b
2 J" T2 J2 i( v' b
public static void main(String args[]){1 I- S5 m% f6 [/ E7 q5 U
int total = args.length;- i: c4 j5 ]: F% X: Y
int pairs = total / 2;8 _' `7 B, ]& u
TQC110 tte;
2 i. I* j5 g: t3 S5 f if(total != 0 && pairs != 0)
3 t$ X" U( @9 i9 R% q% ^ {
7 M/ w+ P6 E: j, j$ {8 \# { //get value from args..
( J' k$ ?! q" D0 H4 {! } String[][] tt = new String[pairs][2];
% \! W+ O v2 E4 c) A( B8 C* b for(int i=0; i<pairs; i+=2){. [. Z0 w1 z r- G3 c) s
tt[i][0] = args[i];
g$ E) g. a. f" s tt[i][1] = args[i+1];
2 O" F4 ~) ]7 G0 X1 F }/ s# g7 R, }' a2 g, Y
tte = new TQC110(tt);* j, y% y( I5 W
}else+ p" B7 H( N* q, n& J% w
tte = new TQC110();* u F' S5 ~! P; l# {
tte.start();
% S3 w. S S- U! N4 j5 F$ w }
) ^0 h% }3 V) b& ~4 J" g. F7 G, w& {; k) h4 q
TQC110(){. K- f5 J* }. J' c
items = new String[5][2];
- }9 z2 K1 k- D6 D% _5 Y items[0][0] = "電腦";
9 u' B3 ~0 v) }6 P8 W9 ^7 r4 `% i+ A items[0][1] = "computer";
I) b- a) B4 y1 ?2 w/ n) i! \ items[1][0] = "資料庫";
1 k+ ]4 ]" ~9 p0 Y0 Q6 `: ~2 H t items[1][1] = "database";
! k4 W4 E, K# \& j; p' e$ Y2 T items[2][0] = "語法";/ s3 a; S: i& q& l1 n: o5 e4 ]
items[2][1] = "syntax";
4 F. ?( y( l* H) J items[3][0] = "學校";
/ R9 y% M; `( v4 }' d8 j$ r5 N items[3][1] = "school";
% L2 Y6 ^& E3 {. H3 p6 X items[4][0] = "假期";
! G+ p5 }1 `) ] items[4][1] = "vacation";) y# l, H! I/ B& `
//make default value
: ^# M! z# h. A+ f: a. b7 O& F br = new BufferedReader(new InputStreamReader(System.in));& F% j) T: \6 N
}
0 y6 n* L8 i; F2 \: Z) V1 Q$ l 3 i- g7 @ q$ u* S+ [ k
TQC110(String[][] it){
3 L( q8 t# F ]( h) a items = it;
' j+ N. C1 G8 ?( d br = new BufferedReader(new InputStreamReader(System.in));) ^. C0 g6 A% d y( a: u: E; w) |
}
; N8 l( r$ {: S
% [6 |: [9 i/ \# C$ ^ void start(){
" A) c5 P" O) v7 w" o; M) t String ans = "";
, x" x' V6 ?- B: O, r6 x* _ int correct = 0; // 計算答對題數
7 I; J0 |6 |) X5 H" g8 T d = new Date();
6 C" {& F; y' S, s0 O$ h start = d.getTime(); // 開始答題時間# f2 j& ~- q @3 E
System.out.println("請將題目的中文詞彙翻譯成英文單字!");5 R E9 T) z% X
System.out.println("輸入英文單字答案後請按Enter鍵:");1 w( K% V& r! X7 Q/ R
System.out.println(" ");, d& t: R& _7 f7 M
for(int j = 0; j < items.length ; j++)( g) K8 J2 o( ], z4 O7 T
{" A) p: J* W% Q9 V% e/ `
System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
, U3 @( \ N4 a: ?/ t4 Z: [ try{
' U3 F _3 S3 x) N/ w$ K' x ans = br.readLine();
, h3 M$ x# r% z8 Z# C3 `+ i! h, W }
: K0 a/ [, s! x) T! r A) C" R! \ catch(IOException ioexception){
; J+ O7 @; v' {# B2 E System.out.println(ioexception);0 V+ v( }1 y" D& ]" I
}; _3 Z& \0 @# N) I N3 ?4 t7 k
if(ans.equalsIgnoreCase(items[j][1])){$ W. P9 \( Q- g O0 s0 }
correct+=1;) J; q) L8 o& n. t' I
System.out.println("答對了!");) |6 z' C6 v6 T- Q
//count correct, H, {( F B' |+ U, l% i5 P/ t
//ouput correct message) b/ b( X0 a# A) }1 e3 [
}else{4 n* A! Z2 j7 Q2 U
System.out.println("答錯了! 正確答案是:" + items[j][1]);
7 W1 P' U4 }5 ~- ]) D" M //ouput incorrect message6 G% j n) _$ p0 U4 x5 w0 @+ A
}4 t. ]' L2 g. E
}: X2 B0 y! }6 z# G
1 k$ y A* z; I' P+ @5 m! h6 r
d = new Date();, G5 V) u& V: c6 U! o; p
end = d.getTime(); // 結束答題時間7 T. A9 ]0 ]: R" |$ _
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");
* s4 i1 \& g; @/ j* s System.out.println(items.length + "題中答對了" + correct + "題");
& j1 g {4 e6 k P: t }' p3 U, ~0 K. x2 k$ _% z
} |