TQC107
, E- n- m: s* l: R/ ]public class test{
' S4 Q! Q7 U @5 K
+ P2 l" J/ S7 Z: {, C1 Q1 d public static void main(String args[]){# b" K& o {- i/ G% l9 P
6 h- @0 P6 c' Z/ n7 V1 V
//0 1 2 3 ( K! o! C$ a( E0 u2 @. q1 g
//1 1 2 3
. v$ T' U+ e. R$ C //2 1 2 3/ ?2 |* d4 y$ q2 c! J+ A( S
4 ?) x) _4 `5 v5 L- t float tot = 0 ;* B& h$ n$ N4 \- h; L
for(int i=1;i<args.length;i++){
) J7 \# g' W1 v# V) ]4 y tot += Float.parseFloat(args[i]);2 U: w+ l6 @" _ x2 X4 s$ e o
}: e& p V ~$ j* p. x( E1 ]: c
tot /= (args.length-1) ;
( a( k" c$ J( n& g0 T: [
, c( o. G0 ?7 | if(args[0].equals("0")){
/ {% {! z5 i6 {( A7 j) C System.out.printf("平均值:%f",tot);% R' v3 d& R s B
}else if(args[0].equals("1")){" E) [2 p8 A8 A8 l7 \) e) m7 o, V
System.out.printf("平均值:%.1f",tot);) p3 V2 U8 g2 v! ], u U
}else{6 H$ I; ?+ {* F( D3 C5 z. c
System.out.printf("平均值:%.2f",tot);
$ E+ s3 \# p0 K }/ u N0 V, u5 O. ~. h1 @
4 a, v7 [$ K2 t. Q& b7 T, G: P
! F& M" C1 v4 ^' Z( ` }
! m: |/ q! K/ J7 D+ Q' e( Q6 q# `/ w, T+ {, U
7 F- D* F2 Q4 Z1 B}
( W( Q" H7 e' P/ z% eTQC108' Z; r L6 `4 [) `! P( A6 W" I
import java.lang.*;
+ k; L1 C! I# d! f7 X) _+ U
: d0 _( d0 Y1 n; q9 x3 A" _public class TQC108" T1 O6 f$ T0 ^$ e, Z+ U
{
* M) Z' o- G9 x2 n) g+ | public static void main(String[] args)
7 _7 @7 w4 F& X1 M2 ~2 X {
. `3 |0 G( }& Y( N2 Q1 ^ for(int i = 1 ; i< 10 ; i++){
{* `2 m! ^6 N8 t3 P; @5 Q for(int j = 1 ; j <10 ; j++)1 J6 P0 X6 t- H6 y5 d% q$ x( G
System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
# q' [) `# y5 R3 M# q System.out.println();
8 k' _) H& R. ? d }5 Z% G9 k* H1 ?, N
}
) E- }8 @/ M* ?6 W}
# L6 n" L2 P7 ~( W" q
1 r0 |- q# y+ C7 ?) Q/ R8 M% N
p7 T0 ~$ L- z' H2 D& V8 }TQC109
/ c/ S% A/ a' R* o: Ppublic class TQC109 {" G7 E) m' d" Z: s( Q: U( u0 o% @
public static void main(String args[]) {+ C' T0 a: E# k
int r;
( w3 y( I1 a0 r0 W r=(int)(Math.random()*100+1);
0 C# l9 N0 T0 v4 }8 E0 e8 } double area = r*r*Math.PI;, { u. g! n, {2 L$ z
double vol = r*r*r*Math.PI*43;) m+ c* q2 Y; g& v% X z' u' F; T
System.out.println( "隨機產生的半徑為:" + r );
+ B' i: e9 A3 U1 H System.out.println( "計算後,直徑為:" + (2*r) );5 z- O7 ^2 P" z1 y: X% W7 Z
System.out.println( "計算後,圓面積為:" + area );. M* `2 B. z9 w" t5 {% g$ H3 ~' s
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
, @: o4 x% |4 _: L8 F" ^ System.out.println( "計算後,圓體積為:" + vol );
5 S! k7 J' F' r) v3 r System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
; ]2 k" r) S: ^ }& W' ]- o7 |0 y/ e3 a, }
}
. N5 N# ]! M6 K2 t2 U
: @$ L7 ^) y3 V5 S9 g ) v* T. J/ c0 i0 k
TQC110
9 O8 V: k( z. f1 {' F9 `import java.io.*;! d- [" k# z1 y% \- A
import java.util.Date;. K. P/ a Q V
: ^7 @/ G) s) W3 p' d! V- W. o class TQC110{
- s5 t) e) _, J& Z% g String items[][];
2 i+ y" _( T' j/ ], v long start, end;. X5 f6 Q( v% _0 ^
Date d;
% d5 S2 U( Q3 Q$ T0 ?7 t BufferedReader br;
5 G" Y, s0 L5 g# Q! p
& |9 h3 T7 Q J( \ public static void main(String args[]){9 {4 A; ]; j$ M, v
int total = args.length;
5 y8 [4 q6 ?0 P. K! I int pairs = total / 2;
$ h( v/ c) L U; H. F- a TQC110 tte;& p- J3 j1 a! Z4 _
if(total != 0 && pairs != 0)5 Q2 {# Q% G: t7 U. R
{' R B0 b+ k) l! d" C# _8 {
//get value from args..
) U" n# d* m9 F+ ` String[][] tt = new String[pairs][2];8 E- E: T# L+ P5 n3 O
for(int i=0; i<pairs; i+=2){( @, U/ D& {+ c% I/ O c8 o
tt[i][0] = args[i];& h0 ?9 v- y; ?2 I
tt[i][1] = args[i+1];" r! C' b$ s- m4 I9 d# j( i. D
}
: U- R p8 N5 j3 X, R1 Q# _ tte = new TQC110(tt);; r$ v7 X$ m4 G! r: n2 S/ d6 ]
}else- C4 A5 B' ?" A4 `
tte = new TQC110();
5 q, ~. y- [# q7 B9 j tte.start();! C8 C- p, j$ G
}
+ K7 H+ ~9 ?. w
' N: h. N7 w8 X/ s TQC110(){
" h, H2 i6 I. \9 z1 P" t# D items = new String[5][2];
/ }% Z$ ^7 K2 } y- ]: l$ b. E items[0][0] = "電腦";, |# A0 d: b1 l; _: b7 F. N- |
items[0][1] = "computer";
6 b9 o* n B- Z) |2 D+ P' t. f items[1][0] = "資料庫";
, ~1 Z- |0 K. _ items[1][1] = "database";
; n3 o3 l& M0 C2 j items[2][0] = "語法";& H8 q. x: K- ^% k; g9 e
items[2][1] = "syntax";9 E4 q6 x* x/ b1 R" A5 H
items[3][0] = "學校";& [: J4 y, y: ]$ W. L9 r- T1 D
items[3][1] = "school";* }+ [2 x/ ~- \- Q1 {
items[4][0] = "假期";2 v, _/ G5 k6 J# f
items[4][1] = "vacation";! O0 z2 t0 Z7 T7 i$ M' ~5 L
//make default value9 S7 e9 s+ B `. T2 ?) a* N
br = new BufferedReader(new InputStreamReader(System.in));5 {8 }8 k" U1 k6 n
}
( E$ {1 D8 v, U: P % Y3 Z) u/ x6 o" `) l5 x, G: u3 c
TQC110(String[][] it){. _$ e6 @- p$ i" k: k5 V6 I
items = it;
; Z1 {4 I; @9 C br = new BufferedReader(new InputStreamReader(System.in));- g0 ~6 Q/ f7 L2 J, [
}7 y1 a- Z) [) g; x- p
) r+ `3 `" K- y/ H
void start(){
) l# `5 b4 V9 [0 f) a8 q String ans = "";
$ z8 V0 B k- e* V H! u int correct = 0; // 計算答對題數 {) z# \* d$ b) V- H# J
d = new Date();, W4 `" d. v, N" y1 x7 |, c
start = d.getTime(); // 開始答題時間
8 e# P- }: D" s p, [8 }- \3 x& ] System.out.println("請將題目的中文詞彙翻譯成英文單字!");3 ?* b7 d1 K' k0 W+ T
System.out.println("輸入英文單字答案後請按Enter鍵:");" ^( Z. q1 ~9 w* O; e- f) B
System.out.println(" ");
& s5 q8 c! }8 |, u/ D* n for(int j = 0; j < items.length ; j++)& F( L1 G* F9 P# v
{
; }7 o$ i" M b. [* Z System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
8 t8 Q6 Y6 H6 y1 | try{) P6 Y0 T# f% B0 F5 i& S
ans = br.readLine();# |+ j' M) j, \1 v
}
7 v$ p! v& e4 R/ K3 s. H* M& z- {4 m catch(IOException ioexception){4 d! l, z5 Q( T0 q: Z& ?
System.out.println(ioexception);
2 Q3 F, }; Q* g } |) D/ M& J: y) H6 a; W+ S
if(ans.equalsIgnoreCase(items[j][1])){, K7 q, W, @/ i0 d/ J
correct+=1;" F& }7 b$ v9 |* j- \
System.out.println("答對了!");
0 p* s1 j$ b5 o0 e- o //count correct0 i6 O a9 i/ S
//ouput correct message+ t# b1 o% N5 ]* i3 V1 u
}else{
. Y+ H6 B9 |% p" c, l! i System.out.println("答錯了! 正確答案是:" + items[j][1]);6 v6 B$ P& L2 _ l
//ouput incorrect message: k4 ]+ C9 X# H" [; h% N
}- ^* D( X3 ?; Z- v3 k J
}3 b6 F+ _# p5 o+ `" D9 T( w, x
4 `% I. P, t1 Z
d = new Date();
* B) @0 C6 m# k+ I end = d.getTime(); // 結束答題時間: D4 j; _' ~9 C& c, a/ c
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");
. [0 V$ O: P% k" ~" ?/ L System.out.println(items.length + "題中答對了" + correct + "題");$ z/ V* V* x) b9 N! E
}
3 A4 ?) P5 h1 j% \' O } |