TQC107
* |/ u6 w9 w4 u q1 n; Ipublic class test{
! e" V. b0 M& o1 }
7 l/ L( ?- k- M2 W+ _# U! D public static void main(String args[]){9 H$ o. U [3 _1 B
5 c }) ~$ X/ |$ n( I
//0 1 2 3 1 S# Q$ Q* u4 y U
//1 1 2 36 N1 L& ]5 U# Q! s4 P3 ~
//2 1 2 34 C5 b, W _$ a
5 X4 Z' i! g% |! {( t' v" f
float tot = 0 ;1 v. W, P$ l$ Y
for(int i=1;i<args.length;i++){
- b* ?& r/ r! f: K6 F tot += Float.parseFloat(args[i]);8 c; O8 c/ E5 n( y- m
}7 H! W9 [; R7 Y) C1 u
tot /= (args.length-1) ;
& g" C' e, R5 X 7 k6 v, g( O( q8 ?$ _
if(args[0].equals("0")){3 T# a. |; C6 }+ C9 y
System.out.printf("平均值:%f",tot);
7 g) e" S S# o( b1 P# b" o }else if(args[0].equals("1")){. V6 L v" }1 r
System.out.printf("平均值:%.1f",tot);0 _5 F }& j2 _& i# u# A
}else{8 ^ m1 T% w M: E8 E
System.out.printf("平均值:%.2f",tot);
/ q0 `' O1 t0 {! b1 } }
5 Q( b) z# D0 v8 V' D
+ z2 P; T$ {8 y, [" q
+ {. i& U% j2 O" d" B }& _7 N' l" F: M& s) @; }
^) R o0 |# ]: |2 v) ]. y
# P d( h* t ~9 \ h}% k( e" b. A- V2 `6 Z3 z) ]1 b
TQC1089 W3 c+ L# O. p3 g, G" ]% d* }
import java.lang.*;. [: F7 ^. ?. m0 z0 `" j. W
0 ^/ K K1 o- c! Q3 ]3 G
public class TQC108 [7 b4 O, r* t. y3 u _
{( x0 B& j# R. i4 q
public static void main(String[] args)
1 Z; |" E- P$ i {
( R. C6 ]+ ^) G! K! w0 Z. S- o3 i for(int i = 1 ; i< 10 ; i++){
. o) L9 F) W/ v% c9 G for(int j = 1 ; j <10 ; j++)# i! j! G9 H2 o) b, F9 S' H) T: c& ~
System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
" P( b! J- S M& F. n/ A, G System.out.println();
9 V1 H: d5 H2 C6 t }5 K/ ?. X, [* D) W9 G+ C% p
}
: [- ], e. y# ?' Q4 o" s8 d! q}% p( q$ k8 u: n/ V" ~ X
8 c8 p! A6 Z6 ]# w
% m0 e& G! c" LTQC109% L3 s# t) ^0 e) h
public class TQC109 {# ]* D1 n* B1 n2 l* G
public static void main(String args[]) {2 }) r B5 m5 _: T( Q/ I% V/ z3 o
int r;
2 E* q4 l8 j7 R a/ |4 n r=(int)(Math.random()*100+1);: `2 Q" }. s \
double area = r*r*Math.PI;0 Q, I, f- Q1 l4 z6 x
double vol = r*r*r*Math.PI*43;0 S+ z. y/ k) O6 J( |+ o9 O
System.out.println( "隨機產生的半徑為:" + r );* V* t) N" U! G1 R) n9 d
System.out.println( "計算後,直徑為:" + (2*r) );
% O' U g5 }) Z& y8 [2 [ System.out.println( "計算後,圓面積為:" + area );# N1 A, |1 m: J8 Y0 U
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
5 q7 g! S& x: i, u+ E$ l- g System.out.println( "計算後,圓體積為:" + vol );
3 `3 g4 u" H$ V9 f System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);& p5 X% C7 C" G; v
}! p# x% ]. b9 m4 S N
}
5 G! j5 i6 y5 ^; Y/ e& i* S% z8 f9 b* v# Q4 F0 u' ~1 L
/ u7 ~/ B, X& B! f w7 h4 U9 j2 Q
TQC110
, O' p7 Y8 K! g7 Q; gimport java.io.*;+ Q( {3 a0 S2 m4 p
import java.util.Date;" p: {, ]5 _! @0 @: Q
0 z5 i( p0 u# {: z# M9 a' R R class TQC110{
5 l- }: w+ u7 h! W+ |: L String items[][];
( h6 W/ O4 a3 X: F; }* ^ long start, end;
' R: d0 E2 y7 I7 \8 |: q Date d;$ e. V: y' \: M* e* F* E
BufferedReader br;7 G- N8 B8 _ [1 \& s; M+ g( H
, U/ V5 ` L! u( Z: m public static void main(String args[]){
5 \. ?$ y3 k: t# [) \0 P% I int total = args.length;
4 Y4 `- m. Z+ K/ [& D2 {* g3 ]' P int pairs = total / 2;
! y4 c9 W) i! T n TQC110 tte;
' M% Y$ V+ k- \ if(total != 0 && pairs != 0)1 c- I* o$ ^* [' k( N i6 f& Z
{
! o1 z3 N( x5 [. y+ S0 V //get value from args.. }" @( w+ D. \8 A0 }! m
String[][] tt = new String[pairs][2];' p8 p$ Q0 H1 K2 b9 ?+ o# Y
for(int i=0; i<pairs; i+=2){; x- k$ Y. ?5 ?, x! t
tt[i][0] = args[i];$ L! D6 \8 o4 n- p: W8 Z* b+ }0 _2 f
tt[i][1] = args[i+1];; [% s# d. X) v8 {
}$ b( w# w! U( c* b& |% s
tte = new TQC110(tt);- B; W( X- [$ B. s& k
}else" Y. J: B( R' R% a5 L5 K
tte = new TQC110();
& f+ k- W' l5 h5 X. @6 `; S& c tte.start();
5 ?- \$ f. Z* {; b( s }
; y' V8 m. }& P( J& u- r# h, P9 m9 s6 {! H3 n* W
TQC110(){0 |+ `/ _, d0 R$ |$ P
items = new String[5][2];
r! m( O e5 ^/ x4 P( ] items[0][0] = "電腦";2 A C: e ^' `) `& @0 o7 v
items[0][1] = "computer";
0 c, G$ L* E* v s2 m$ n( C! E* j items[1][0] = "資料庫";- s7 K1 o4 o1 D# t
items[1][1] = "database";
1 Q h# T+ V, ^+ s; h items[2][0] = "語法";4 M3 ~" a5 E" d, N
items[2][1] = "syntax";2 }# ?- u0 M: s' V
items[3][0] = "學校";& d0 n# P% R) P/ E
items[3][1] = "school";" d6 v$ s* e! C. h, U
items[4][0] = "假期";& I9 l! E m0 c1 }, V2 x. p
items[4][1] = "vacation";
6 C0 p4 F' e* z: ]# ~# s8 ` //make default value* L* C7 e @! [. Y0 V' }
br = new BufferedReader(new InputStreamReader(System.in));
: w* @9 a \# V0 a3 c4 S; P' T }8 R8 ?2 D* b* k7 b2 |* b* n, u6 D1 d
' X3 Z" j$ L( Z& ]
TQC110(String[][] it){
* W* A" z( K0 v items = it;3 f( d. h8 N( J$ [) }& _/ H7 P
br = new BufferedReader(new InputStreamReader(System.in));- h. g" ^8 f! d! u
}
6 S- } y d0 m& i - \, i. ]! M8 T- `$ ]
void start(){
3 l3 w: d4 y4 a5 { String ans = "";' [% N$ s I4 B1 y* H
int correct = 0; // 計算答對題數- u+ T) l4 g" X1 Z% H& s" n7 i7 S
d = new Date();
0 O2 V& z7 C! [1 T4 F# J start = d.getTime(); // 開始答題時間% B9 j( j; c: }2 z" l" ~
System.out.println("請將題目的中文詞彙翻譯成英文單字!");
2 p; G# d# H, C+ g System.out.println("輸入英文單字答案後請按Enter鍵:");
s4 Q0 K9 @9 u' ^ System.out.println(" ");
& ]# ^5 E+ }0 D. j+ Q s% \6 c, R for(int j = 0; j < items.length ; j++); w7 z, D9 e; @. T
{
4 b- c1 {6 R9 {7 t" l; Y/ J System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
9 f- x9 q& {, B# A try{
) v2 v0 A4 L- _3 {9 o ans = br.readLine();' N, b" B: {: [
}- u- Y" A3 H$ O% P- _
catch(IOException ioexception){' b: i2 A8 T! E5 v" d. T% [
System.out.println(ioexception);+ O7 h. Y) \7 H; T5 v: v" z
}. \* i- A' G' [
if(ans.equalsIgnoreCase(items[j][1])){0 s8 _3 Y$ d) W2 W% Z
correct+=1;1 n6 |, z! r, e: U2 `2 F
System.out.println("答對了!");( H) T B0 z6 ]
//count correct
# v# U1 U- p$ n/ V, j3 Z //ouput correct message5 q# s+ L( B$ n
}else{
# x0 F$ h) F4 I% V3 V: N' x System.out.println("答錯了! 正確答案是:" + items[j][1]);$ i2 n1 l" [7 m+ K0 e i- v
//ouput incorrect message; L1 x" E% K: Z% o
}
6 M$ _( C. p* J }3 P7 r1 V) ]4 L9 i% m
9 v; _$ b# _( ~% I/ F. n! T
d = new Date();
8 I9 o* G& l) k( X end = d.getTime(); // 結束答題時間; g! P; C+ f" s# z8 G
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");; o" P9 B- L7 h) o5 ~9 T
System.out.println(items.length + "題中答對了" + correct + "題");" ~9 |. W- }5 L. _/ k& I7 ]& r
}
: i+ K: x$ ]* ^/ M } |