TQC107
9 V. u# H0 V3 x" E) ] F# ~6 cpublic class test{
6 g# E/ C( B. W- L# O/ i& @) `" n8 `
public static void main(String args[]){ d, z4 a6 [8 F# n
" s+ W; R4 N- M# U& e' Q //0 1 2 3 & |" E. S: k; s* Q8 S b4 e8 ]: @
//1 1 2 3
+ H( Z& x; ^2 }8 S/ u //2 1 2 3
) e( J6 j( Y% S' \' j+ X ! M8 a* C6 g8 b8 D. ^3 i
float tot = 0 ;
$ P4 P' P' g" r$ |; g2 Q6 ^3 T for(int i=1;i<args.length;i++){
4 ?% o3 U# c; ?; ^ tot += Float.parseFloat(args[i]);+ y3 o* s' ?% J7 @' ?4 A% x9 e
}3 r: m, o7 j ]" |: c
tot /= (args.length-1) ;8 |7 O0 b0 C w: W+ a, T; R
/ R5 ] p9 G. |' A
if(args[0].equals("0")){- Y5 k1 b: R S; L. j U( i: R
System.out.printf("平均值:%f",tot);8 C3 O( v! G* s3 e) a# k
}else if(args[0].equals("1")){2 z6 f# ^, z8 S( E8 G3 k
System.out.printf("平均值:%.1f",tot);- M* v+ l5 } o* c
}else{
3 @& I. y6 |% O System.out.printf("平均值:%.2f",tot);5 r7 v4 e& E' n# }- w0 a( W
}
# b8 ?( Z1 r; a8 g+ E0 N
* J( t# h& R8 M0 Z
. _: c1 H& P, F- p }
4 R* \ i- q7 G1 [4 ~) R" d2 w. L) y9 [+ u' p1 v, F, R# E# }0 h' b
6 N8 _' y' \. Q}; m4 N) P* a% }/ G% m
TQC108
. O9 d2 u% g8 v) s7 W) z! l: Jimport java.lang.*;, a$ k2 D/ [! z- p; ^4 B2 Z- N- ?
' o7 k2 {& K3 E; }# M7 qpublic class TQC108
& {8 ^- F) w& N- o7 d{: }9 c* W$ Y8 z# u0 c
public static void main(String[] args)
' Z/ ?- f8 X/ B% x/ j: l9 Q+ X" |4 Q8 I {3 p6 a: b( F8 j6 L, @
for(int i = 1 ; i< 10 ; i++){- Q, g- V+ }0 W: t$ Z% `
for(int j = 1 ; j <10 ; j++)! X- k! o( D, E0 y8 V
System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
0 [9 t b4 M9 p# j U System.out.println();
* G/ z- }5 m5 o7 c+ o& f( w }
" w0 K6 z6 B0 Y3 g }
" }/ t: x/ V2 C}
0 x1 A3 S9 p+ E6 M- u8 `' m4 i' P1 Z' }. D0 j* ~% _
- `$ [4 Q4 ~/ o4 a: r) A
TQC109
9 X! z& `3 S; D, |0 s9 _# fpublic class TQC109 {
0 n0 C& A* p+ M* J8 Q public static void main(String args[]) {
) j P, q7 m( _: ^& B0 ~ int r;
8 u; h9 C) z$ {5 P7 w+ I' C3 } r=(int)(Math.random()*100+1);
' c& M4 M0 G |9 }3 _ I1 Y double area = r*r*Math.PI;
/ Y' |& U$ X* K+ O+ W: Q3 ^ double vol = r*r*r*Math.PI*43;6 \) m9 X b' O" Z. e# [4 u
System.out.println( "隨機產生的半徑為:" + r );
8 ~ R W" C1 R( z System.out.println( "計算後,直徑為:" + (2*r) );4 O5 t( [) d) M( T( {+ K
System.out.println( "計算後,圓面積為:" + area );' I) q2 U/ s; t' L& j
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
4 Y: ~1 i# \2 V0 t# q; F' g! D+ I+ r System.out.println( "計算後,圓體積為:" + vol );
X4 T: J' ]) C; n) y) O1 e; | System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);& H% V) C' {/ h7 V4 ?
}/ @/ Z2 e: U* n
}
2 W0 }- N. B# j9 ^& e
5 H; J) w m0 s; o 8 @4 I& S' ]1 R$ x$ A" ~
TQC110 + d; y" H0 t" F* A0 k1 y6 T" g
import java.io.*;& K) R/ E E& I8 ^& j
import java.util.Date;4 |$ h& v. z" z! M3 V6 U
9 W3 _( \3 H0 n ?
class TQC110{7 M. X9 M/ |: T: u" V9 k) P
String items[][];& H5 t' t8 x2 B5 K" _8 S
long start, end;1 @, T' r/ T3 h2 y; [
Date d;5 Q2 W9 [3 V4 \! k8 w
BufferedReader br;
# R' Z8 {5 |* e) u+ o q7 H: o, S; [/ i3 _7 J% V O# v
public static void main(String args[]){7 h& N0 t9 H% ^0 \; N
int total = args.length;) K' l# d: r2 W# \ G
int pairs = total / 2;
m& T3 v' n; t6 V+ ^/ ? m6 w TQC110 tte;1 X8 d* F* W# h/ L# b. Z5 i
if(total != 0 && pairs != 0)7 `, \( _ o. d4 l4 y" d9 t$ O
{! j1 s( |! m# j) Q, P( S8 T
//get value from args..5 {8 @* J% Z3 U% k
String[][] tt = new String[pairs][2];) E& I' q7 _0 }& m
for(int i=0; i<pairs; i+=2){& K1 [) \1 _: f4 y
tt[i][0] = args[i];/ Z+ }% q) `2 ~" Q0 m% U
tt[i][1] = args[i+1];
) K- q' I, L5 u8 b% V2 @& w3 P }& ]1 W0 Q! x' u- I1 z4 _0 s
tte = new TQC110(tt);
! U5 n% a$ t0 p& }& Y+ v5 b+ v }else
7 a7 j; U! i* K tte = new TQC110();6 s; h1 k) J/ p) Y$ |" J! V
tte.start();, O/ u7 F! G* i/ {0 n, j4 q
}5 D: H1 k: M2 E& O
, _+ z5 ^: V4 b$ f8 O) g5 | TQC110(){6 |, E6 V6 }! k( Y
items = new String[5][2];* Y+ R' h4 H' x9 ^! n: j" ]. F$ B3 g1 ~
items[0][0] = "電腦";2 @ S; W* E& M& _
items[0][1] = "computer";
+ ^, T- B1 C. H7 O5 }- |0 N( g items[1][0] = "資料庫";
5 e5 t, L( E" h items[1][1] = "database";
) n' S0 l7 O/ w$ n4 e# T items[2][0] = "語法";2 p! j4 a, I Y
items[2][1] = "syntax";
- I. q/ h" ]" M& g# J. j' E1 } items[3][0] = "學校";& l C2 h5 ?: e4 C
items[3][1] = "school";- l! P! \7 a8 x
items[4][0] = "假期";5 a$ a) I$ t* J% a
items[4][1] = "vacation";
0 J% k. K) q1 S N //make default value$ x' n5 {) ?6 H; f
br = new BufferedReader(new InputStreamReader(System.in));
' A4 O- o" P! {6 [; _ }. O( n7 H5 l$ d$ j+ C% L* }! d
- f9 R2 G: u4 A3 S$ {
TQC110(String[][] it){1 N1 X2 {# c! _: u
items = it;
4 u; s4 k4 o/ V2 P+ O br = new BufferedReader(new InputStreamReader(System.in));/ ~1 }8 O( \ `8 S$ E
}: Q: O: v4 s$ o* E2 D h: E
: H# c" g) Y7 K/ } void start(){
1 U+ W; b7 W2 I# _ String ans = "";9 ~2 S) f1 G- f: O9 f, z! z
int correct = 0; // 計算答對題數, a- x0 H" s& z3 h8 b& Y8 ~
d = new Date();# d- ~$ J6 e0 I% @6 [, h: X5 U8 h
start = d.getTime(); // 開始答題時間9 k! o8 N) o$ b- m2 t! e
System.out.println("請將題目的中文詞彙翻譯成英文單字!");
9 @" `, _2 m( I5 T: P$ J4 E System.out.println("輸入英文單字答案後請按Enter鍵:");8 N: U& \, E0 d2 @8 E
System.out.println(" ");
; Q7 S% `4 q8 R2 [1 Z for(int j = 0; j < items.length ; j++)
4 ^& J' |% t _1 G {
: e- y, k. j; F System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
! N* \& g* G) m' S( C* S try{5 ~) v; e! P, P. z) n! [
ans = br.readLine();0 L" ^5 C( M6 ]
}
: a9 i6 V( l# [! l9 f. ^ catch(IOException ioexception){
- ^7 h: ~5 @: \+ l2 D9 q System.out.println(ioexception);" A& p8 Q& ?- Y A. O: ^/ X5 O
}7 s v) `% d" C/ z1 ?6 ^9 P
if(ans.equalsIgnoreCase(items[j][1])){
' c+ v; t% T& `* D& W F correct+=1;* l- {4 v0 b6 M# ]
System.out.println("答對了!");
. t+ B( I! ]0 n! k; h& | //count correct0 n, V$ {4 G; P! E1 W
//ouput correct message
. M; S4 l9 r0 K+ Q+ ?; e }else{0 r9 l6 k# s/ d1 \( `: X$ Q
System.out.println("答錯了! 正確答案是:" + items[j][1]);
' a. e; _. s) X3 u9 z, A* [, i //ouput incorrect message: u8 {" C: P, ?. {' l( x
}5 i2 n. h Y+ B3 B4 T) C6 E
}
2 E9 C L9 n7 @# z& z& k R* T' u
d = new Date();/ Y- ~% X! d* g- M
end = d.getTime(); // 結束答題時間
6 Z' c- Y; Y3 G/ b1 _: J System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");! K9 K; y& x- x# _& X
System.out.println(items.length + "題中答對了" + correct + "題");
& Z9 f- K6 w3 H! ^2 N4 B3 F }
1 h( g5 W6 @0 H: Y: G } |