TQC107
# c( E2 o- X: J. @; mpublic class test{3 O! R; b# K- q
) o# a: S. [3 S$ O, \+ n( V) V
public static void main(String args[]){
8 B" B+ ^/ v( e$ a
; v0 \' d% u4 z# ` //0 1 2 3 6 w7 P2 R _( d. }
//1 1 2 3* w/ {5 g5 n4 C% c. [) K( W: K
//2 1 2 3& I. N3 i _( c4 V1 T1 ]
0 o3 k" Z) J. ~' ?2 ^- M4 I8 X$ E( O float tot = 0 ;: _) z4 H$ N1 E4 j v+ r) f8 W0 c
for(int i=1;i<args.length;i++){
. a! B' T7 I8 j# }( ] tot += Float.parseFloat(args[i]);
$ M. [- b# p- K: m$ v4 S# a }
' E& H, O' ]8 |3 J tot /= (args.length-1) ;$ `9 P$ D* F0 A- ~, S) B' g1 g( e
: H) c* U' Z' x3 H$ ~! V if(args[0].equals("0")){3 ]1 R g) \: }6 v# M9 N+ S
System.out.printf("平均值:%f",tot);
3 S! ?) G4 U( S" I1 @2 N) v }else if(args[0].equals("1")){
! }1 c4 ^3 J& D* {# z) ?$ G System.out.printf("平均值:%.1f",tot);5 o9 F- Z3 P8 ^9 j
}else{
, U' d8 P- X; r System.out.printf("平均值:%.2f",tot);+ Q1 B! z g7 g
}1 S( i. ?! {" \ p/ q
4 E. m: _0 O" G7 s3 U L
' C# R4 S& Z2 p3 b) b }
# m& I; }9 t1 m! K; V Z& `* z' T. R* y0 e) Y) t4 J: ^; r* [( R+ E& A
1 G2 J8 S& \7 M# f
}; r1 y" t" R. U5 K
TQC108
7 `# n! u3 @4 Dimport java.lang.*;
* m$ e i! _& ~6 I0 L+ m) `+ R3 l- e
3 x2 Q- \; n, k; z, tpublic class TQC108) I: T& b3 l) T7 f# f! C: |0 _: o
{9 K$ c6 y! Z3 I: Y& T8 M. @
public static void main(String[] args) 6 ~( Y6 O4 v! t; _8 i9 J" ^+ y, T
{
% [: f9 v( ^! g for(int i = 1 ; i< 10 ; i++){) [, q3 |* x6 g! H# L! F& F6 y; K
for(int j = 1 ; j <10 ; j++)8 K* L& T# X/ T+ X2 d5 r; |; t
System.out.print(""+i+"*"+j+"="+(i*j)+"\t");2 K7 B0 E1 |) b2 g' V: d; K0 J, T
System.out.println();9 x3 _% _% m4 u1 z
}8 M! W) t6 U) U u* D g
}
& u1 u! K7 e1 d' ?6 b}( @9 _3 [- Y* [( x# A0 L- S6 P3 o
, Y9 d' p7 k4 E* a) j
0 I( v" t- f7 Z* T
TQC109
1 a# [0 S" B2 L- e2 O9 Wpublic class TQC109 {
0 g* k! `# K5 o \' m* H) e public static void main(String args[]) {
5 I: c. A& U H& e2 {) `9 } int r;, O* r+ a0 L3 k+ _5 s
r=(int)(Math.random()*100+1); c3 w" M* k) G; |8 f8 d2 a
double area = r*r*Math.PI;( C" Q7 ]6 l% y) ^4 z) I9 @+ x
double vol = r*r*r*Math.PI*43;* P" @% J" {: y; m2 B1 p' O+ O
System.out.println( "隨機產生的半徑為:" + r );, J, G* U% H7 h' X$ I) C" L
System.out.println( "計算後,直徑為:" + (2*r) );4 o$ J0 |. I/ N6 a3 c; h8 U
System.out.println( "計算後,圓面積為:" + area );
3 S J2 u, e8 E1 {& L6 D System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);7 a! _9 M. T( e h3 A2 u
System.out.println( "計算後,圓體積為:" + vol );
$ R& ~% u4 v& b7 L2 W0 u7 o$ B: N System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);- Q9 N, `$ ~& @; V
}
2 e; O! G/ ]: |$ R* ]4 q3 I}$ k" n" k! g7 f, p% A8 r q N
4 E- ?: X& v0 I+ @% B# U2 ]7 Q
5 J. Y! E; e2 ?% e- X/ M- c7 m' r' b7 g
TQC110 2 w' V! z5 A: p, e9 ], e- [
import java.io.*;
0 s1 J' N, ?$ C. u( n% i; himport java.util.Date;& }9 t) y1 \! ?! z! O
# F$ b% l0 M4 [ class TQC110{
9 X8 |! `" }( u. ]! H2 J String items[][];
9 J; L: I5 X$ A5 y A# _ long start, end;
, Q2 ^1 ^/ _$ `% g5 @4 {4 ~ Date d;$ W' \4 [8 Q. n2 J0 b. \3 W0 Y# y
BufferedReader br;# C4 ?. f/ J i4 l
- R, h8 H+ Z1 ^ public static void main(String args[]){
5 N4 i! }' j3 Y3 u int total = args.length;$ \- L9 l% G2 K2 N
int pairs = total / 2;
' Q! w3 k, f! x& _' B5 ^' l TQC110 tte;+ h, x6 V; N e5 z- z
if(total != 0 && pairs != 0)
% M3 r x. ? Y. U* s. I) Q {
8 H* X8 ?4 Q4 U$ j6 @; e/ x, P //get value from args..+ E( Q, D$ S- G
String[][] tt = new String[pairs][2];1 w3 v' ?( p! I' ~. @; r* E/ y: K `- E
for(int i=0; i<pairs; i+=2){
^& \- J6 F6 O- j tt[i][0] = args[i];
' m, ~3 D+ y" T! {' ^ tt[i][1] = args[i+1];0 G' n! e, N- _
}0 @2 s$ r( l/ A! u6 Z2 V
tte = new TQC110(tt);
$ K/ e$ \8 f& M$ u }else
' T+ H* ?+ L9 o7 ?2 M5 }+ t1 F tte = new TQC110();
) n9 p7 E" y6 t1 y8 J tte.start();
& L6 |, q% B8 K% k0 D+ O2 X }3 k9 w# `: f! v3 R) o' e' z, Z
* I0 V* y/ r2 Q4 f/ U" h TQC110(){
- C2 x [7 C G0 ?" G- C items = new String[5][2];
4 _0 G& O$ [; c# L& S2 u* v items[0][0] = "電腦";+ O% S U1 s1 N U
items[0][1] = "computer";% Q1 F) ^' Q: _& X: i2 t. X8 Y
items[1][0] = "資料庫";+ `! B* B4 P) i U4 E5 q) X
items[1][1] = "database";; z, F9 U& v7 k" J0 b% U- b
items[2][0] = "語法";+ {7 u: l, C4 N/ r& T2 b" O
items[2][1] = "syntax";
; E* m# y* F& N6 P( x. u, a items[3][0] = "學校";' V+ s( g9 V, r! s$ d
items[3][1] = "school";
( J2 P; ]* \$ M7 J+ b7 a items[4][0] = "假期";. B! H1 H) P% d; \" z$ z
items[4][1] = "vacation";
8 Y$ P8 ?/ p4 V: M' y. K //make default value
7 ?, V2 |# Y5 U i: P' }$ a br = new BufferedReader(new InputStreamReader(System.in));
; o( `0 h. j/ X- m8 P }
% @7 @( C9 @% A. Y ) f7 M7 ~" Q ~$ l, V& y
TQC110(String[][] it){, \! e. V* q+ S
items = it;! Q( r* j( p# Z k+ g
br = new BufferedReader(new InputStreamReader(System.in));% o# V* v: v; ?/ R
}0 V6 x9 }" j0 a
" H8 i8 |- e- Q' {% \* k% [
void start(){9 c$ f) P! V1 _ B) o7 N2 L9 d
String ans = "";/ n# m$ L9 N' W0 l8 N3 X {$ \
int correct = 0; // 計算答對題數0 A. L: @, x: P$ M/ S. q
d = new Date();& y7 `1 f% i9 X {. l% H8 |; U5 D
start = d.getTime(); // 開始答題時間
' G( S0 v* R5 [. ?% H System.out.println("請將題目的中文詞彙翻譯成英文單字!");5 K1 B7 S4 s% j+ }4 V
System.out.println("輸入英文單字答案後請按Enter鍵:");; D5 R" N" _+ q+ c* m5 M, z( U/ B
System.out.println(" ");
4 {2 t: |- O: J& \ for(int j = 0; j < items.length ; j++)! _1 ?3 D( V$ k+ X5 N
{* n0 N( p1 r: K$ `2 Q
System.out.println("第" + (j + 1) + "題__ " + items[j][0]);; @9 l3 y- A" ^; a
try{
, x& v- \* U0 E0 _% R! @% J ans = br.readLine();
1 X9 |- `6 u. w }0 f, J: ^' [6 j: B" H' r+ i8 N; f
catch(IOException ioexception){
* \6 N) T( W, a3 ~ q* v. J) w System.out.println(ioexception);
* P- P0 M9 `7 I$ }. G }9 \$ q6 C7 J! s
if(ans.equalsIgnoreCase(items[j][1])){1 `' g+ @' d' S6 R! J8 X0 g( L
correct+=1;$ [& B2 l$ ?$ \; b- S
System.out.println("答對了!");
& [1 Z w2 v3 ]* o //count correct
/ I$ h" v" l3 F( W( [4 @. O( |/ M: b //ouput correct message
- @# {( T/ f7 s3 c6 s5 J }else{) Z" q7 g5 M) f z. g) I& X
System.out.println("答錯了! 正確答案是:" + items[j][1]);: ]# C) u: G. N* Z
//ouput incorrect message
" G7 ]( k7 u7 s1 d }1 i) V5 P1 v+ x; I% w: N
}+ v& h/ d3 L" J. y* y
1 V( U! a' H# C5 x* Q- c9 i
d = new Date();
! A+ f, O2 _1 S) a end = d.getTime(); // 結束答題時間
( k! z2 K( c% k6 O, z( o System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");+ U& [/ M0 a' M# I* p
System.out.println(items.length + "題中答對了" + correct + "題");
5 y/ ~' D0 ?1 [- X; p }
7 ~* v1 E& [0 f# e } |