TQC107( B2 D2 m# A r2 U
public class test{
1 y* n* |/ [( J9 p; H* V- N' o
/ S) i8 W: S3 \ public static void main(String args[]){
! f# \1 x- n0 n! \: u ; S0 T3 F _/ ], d
//0 1 2 3 ( U3 ~1 R/ A" V
//1 1 2 30 T( m* X+ a: ?" V7 F
//2 1 2 3
6 t$ ~( E9 m" H7 g7 a" S5 w
$ [7 z- _. x3 U8 \. L* Y# I float tot = 0 ;
" f% e; a; R( B% ] t- a for(int i=1;i<args.length;i++){
: ?" Q8 W9 j# H0 b& Q7 S; ? I tot += Float.parseFloat(args[i]);3 S$ M1 w9 f. G
}
; U+ d' ^5 a2 U/ K) i1 [, |& |/ r tot /= (args.length-1) ;
5 _' b, ^# q5 U1 i
. Q3 _, ~. n/ Y; \' p% W3 w; \1 } if(args[0].equals("0")){
. D* i( }, j" d! u6 v8 J% J) x System.out.printf("平均值:%f",tot);+ q8 f; a5 n/ u. z1 j" D
}else if(args[0].equals("1")){
8 I( `( q5 C0 y; P4 C; E% c- ]" { System.out.printf("平均值:%.1f",tot);
# y3 D* R- U O2 m S% d }else{6 `1 d5 Z( [ R6 x
System.out.printf("平均值:%.2f",tot);
# t5 k1 m- `0 o3 Y5 i; Z8 |) u; L }3 ~/ y* h3 F) D- k
1 H5 J* s9 A! F/ `* y" o4 d3 D
( X/ Q, R* \$ K7 K( b- | }
; ~2 ] d) X, `: i3 e) [% N* ~( h- }% N( I; a
( [" E& J4 U1 H7 Z1 C
}3 h9 M7 P% X i
TQC108
/ {1 a4 V" O8 t4 X* oimport java.lang.*;
& t# w# r: _9 w) L+ W4 @- F. _, I2 T) K7 G6 U0 H, d6 y
public class TQC108
5 K# P: t6 r, m{- s- o2 \# N7 b% J! t6 o1 [
public static void main(String[] args)
1 O' Y/ K1 D" R, h# Q {
3 Q& ]9 W; K+ c+ R for(int i = 1 ; i< 10 ; i++){) ?( E3 B; b6 D5 I" f% V' g
for(int j = 1 ; j <10 ; j++)' }5 B- H8 s% h0 z! m
System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
+ D1 s# [) J( Y8 C3 X. h" h System.out.println();$ q* f3 l, ]7 x4 y! m2 O
}
' W& Q( _; i" l+ ^9 r }
: u4 B" {) ]" {. a$ p9 d8 i! m}
0 q7 E- L" F( O: g. A" u$ v
5 ]3 [5 g/ I5 b. D5 d) |2 Z x; {
: N0 i M5 W: g7 _2 E9 LTQC109
6 y* y' O* n9 j. s7 `* t7 [public class TQC109 {
5 _6 K; Z+ |* @) P3 V2 V public static void main(String args[]) {
/ r, d: x5 _: _; Z int r;
! F/ d" c/ h y; [% s r=(int)(Math.random()*100+1);3 y. E. ^0 w) ]' P# l# ~/ Y1 {! K* P
double area = r*r*Math.PI;
; y# U3 z# |3 Z+ A- ]& {; N0 N& ~ double vol = r*r*r*Math.PI*43;. Z& m! T% T7 b# b- E5 H
System.out.println( "隨機產生的半徑為:" + r );
8 H4 e) w9 {% q7 P, v/ v System.out.println( "計算後,直徑為:" + (2*r) );7 H- n3 Q5 Q* M; s( M1 F/ z
System.out.println( "計算後,圓面積為:" + area );' Q9 ^+ m6 H, P5 }
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
6 R4 \/ T9 A; v" c5 D System.out.println( "計算後,圓體積為:" + vol );
+ ?/ Y# I) {$ e4 M# _ System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);/ p8 }, _( R4 R# T! {$ H1 g; F
}
L9 z) o+ N) D3 g# ?4 i/ e) ~}
, t2 }, c3 o! W, A8 u& m
7 ~8 G/ Q5 q& G& a% }2 _& R h* x! S1 M/ F( R( `
TQC110
% N) r# r& }( j6 [1 ?import java.io.*;
% _0 J, J( u2 [6 y. g# j! V* vimport java.util.Date;8 _& m8 C1 p) L
7 O( `" ^/ I0 c! N9 V' e class TQC110{. ?, \% Y, E# ?/ m
String items[][];: Z/ m$ Y& f- }/ d4 u, V
long start, end;
" n, r- ], N7 y3 |! C Date d; `3 T5 y. [& j
BufferedReader br;1 }7 A8 f4 Z" [7 f T) c
2 ^0 _6 L* @! z6 p
public static void main(String args[]){* C t7 r# P; U
int total = args.length;
0 N$ c2 r& j! r int pairs = total / 2;
0 Y8 G1 S0 |5 A+ `/ k" t3 ~ TQC110 tte;4 |# W/ ]" @5 `4 B* k# y' q8 L
if(total != 0 && pairs != 0); a( b# T$ S% I7 t7 E
{8 ?+ D. Y' ?1 V9 _% U, S
//get value from args..5 ^* j9 e% G5 t$ `
String[][] tt = new String[pairs][2];8 _( Y+ F+ N/ |/ M
for(int i=0; i<pairs; i+=2){5 l* ~. a2 ?0 {6 @9 f; q
tt[i][0] = args[i];: m7 L7 b4 m+ F# E
tt[i][1] = args[i+1];$ z; E; W" f3 {4 E$ L
}- p M* g4 z0 p6 _: E
tte = new TQC110(tt);+ B5 ?0 |% r( ^' m7 O0 ]" W
}else
& z& d! F$ O3 K! ` tte = new TQC110();
" I( C# T4 r5 j( u tte.start();
0 \2 T) m) y A9 H# x @- t }% m7 J* t, z9 ?7 p5 r* o
" B1 m: B/ [4 J% B0 i TQC110(){1 q5 j6 i. | L* U U" ^* P% r
items = new String[5][2]; @/ a9 y+ N4 y% `) Y
items[0][0] = "電腦";
0 ?9 C0 X8 `. F items[0][1] = "computer";
& A' C+ i; W6 ]5 g, e items[1][0] = "資料庫";
) A/ s( y8 v0 G5 U# W7 c# t+ e items[1][1] = "database";5 {# ^$ J. N: t$ h; | u: G/ Q; J
items[2][0] = "語法";
5 m' W# [6 u' g3 X6 H& X items[2][1] = "syntax";
* _4 j+ G- v. o6 Y items[3][0] = "學校";
5 p% m+ @ L4 u1 f items[3][1] = "school";' S. C( X- H& X& y7 M% ^
items[4][0] = "假期";- W6 ]$ q! G2 ?/ n* n* d X
items[4][1] = "vacation";
o B/ ^, P; c //make default value" H! ^& j+ s- E; M6 t; m2 i8 b
br = new BufferedReader(new InputStreamReader(System.in));/ l. f; M8 `$ K3 E4 Y& m8 T' W
}
# q; ^* D+ c8 v+ E1 L' v3 b
5 S1 s8 p$ G8 }9 M1 c( ?! O$ S TQC110(String[][] it){
0 g/ J0 l* _" O# L3 N5 A& l4 h items = it;
# ?% X3 D! ], d6 c0 @% N1 D! n' D9 c br = new BufferedReader(new InputStreamReader(System.in));5 a& L2 s, a* l/ H9 ]+ D
}
2 A! k2 t9 s2 Z+ I# m ~9 i' ~ & y) E! Y9 O, X/ e9 f% I8 b5 u- w
void start(){
1 p, ]8 T# h( J% x9 M+ P2 m String ans = "";
: Y0 b0 \# n, M4 g4 x3 f int correct = 0; // 計算答對題數 `9 S/ L8 W; z4 }' { X0 k
d = new Date();( [0 N/ t6 l1 `+ L( D
start = d.getTime(); // 開始答題時間
% ^5 p! ~ k, L7 n System.out.println("請將題目的中文詞彙翻譯成英文單字!");
8 i$ U2 k% K1 v7 A System.out.println("輸入英文單字答案後請按Enter鍵:");- } T5 ^$ ^9 I
System.out.println(" ");8 N* v) C4 O; c. x. q
for(int j = 0; j < items.length ; j++); f4 d) }% }# ?: _ h9 A, F
{
* `8 D7 s: f- t" r8 `4 r" Z" U System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
. [- ^# ` ? }8 }( x/ A try{$ @$ i7 H0 s& o
ans = br.readLine();: a3 z7 ]* r" M# ^0 z# S2 ^! h
}
, e4 Q+ k$ c4 A. y1 l catch(IOException ioexception){+ t5 f: e7 }5 {
System.out.println(ioexception);
" h6 L/ _" U+ }; p# O, p/ c! t }
7 Y! B9 F7 @: A/ n- A if(ans.equalsIgnoreCase(items[j][1])){0 Z2 `8 W u9 `" x1 h
correct+=1;
2 ?. n; u( y ~3 ?: Z* g. [ System.out.println("答對了!");
% _& I; G2 c, l* Q* R. A //count correct
9 X* _0 U- ~6 I" a( V7 R. v //ouput correct message4 \% W! V8 K$ h" v+ ]4 t9 Z
}else{
, e5 a |, O2 G, R+ e1 A) q System.out.println("答錯了! 正確答案是:" + items[j][1]);& b# e2 W4 _ m% A. ? Y' G% f6 l
//ouput incorrect message( t# z/ o: F/ j' G% Q* L
}
; f0 O8 ?. Q2 j5 O& G }
$ R2 l7 u+ J8 M2 |$ D. n% E/ @6 Q1 }$ [8 J# E8 l
d = new Date();
$ o5 F/ C4 k- p- [7 L end = d.getTime(); // 結束答題時間
$ R# k% X0 l4 b: F4 C+ ~( P Q6 F System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");# T! U; k2 n# P' ~) _/ ~
System.out.println(items.length + "題中答對了" + correct + "題");
$ [/ e- j3 H/ E( `' }% E }
" j7 y* T' c; T+ V0 _3 u. q. t } |