TQC107
e, U8 ]9 K E4 o. \& H7 J* X/ Gpublic class test{
\6 f! j4 M* U3 W3 J
/ O5 }- d8 P( g+ @ [3 o2 T1 b$ B public static void main(String args[]){: ?, B* F' \$ c8 n6 k+ ~3 `+ y
4 V- s- V: Y$ R //0 1 2 3 ! B) w) ^6 [/ |7 J
//1 1 2 3
* e7 y1 I, }7 p2 O //2 1 2 3 ]7 l+ C7 K; B* b- @0 T' v
5 E! D; d; O' Z% K2 y9 M
float tot = 0 ;( E! N! b4 L3 S1 ^; x4 N9 `
for(int i=1;i<args.length;i++){
, G# ^ b; E& Q& `4 p tot += Float.parseFloat(args[i]);( b8 x+ l3 I4 t% P
}
9 [) S' c" g1 @& P1 T7 u& E/ | tot /= (args.length-1) ;
$ o5 U6 I; K4 V, T/ z: D6 V+ K ) h& E/ |5 e- X
if(args[0].equals("0")){. \$ z7 n5 S7 f8 O
System.out.printf("平均值:%f",tot);2 |( H* l: b0 L5 N
}else if(args[0].equals("1")){" [# B4 |0 `' {" y7 I7 R. }& N
System.out.printf("平均值:%.1f",tot);- b9 M# m4 F: z. u, J
}else{% g9 f( ^- V+ l( f, W
System.out.printf("平均值:%.2f",tot);
/ ?, Y9 P2 L- i, s }9 Q% E I: I; C" v9 Y$ Y/ I2 ]
# b1 R$ h% n8 \3 z0 h' t+ n. I * P$ f0 B$ z( f' A* d2 Q) g
}, A* L6 G, B8 L) X) H% x1 `
2 C9 g5 O: @/ d6 {) b0 \( H
0 a% I2 @8 c! v}- g. V* F0 W: ^4 |: E; b
TQC108
1 U7 i" c: O G: j, S; a) `import java.lang.*;) ], V8 `6 B3 `- `' A0 c
7 r1 V f9 R5 T: z* `3 S
public class TQC108
, E# |3 m% ^' N5 h" ?{
5 d7 O5 i4 n9 b3 A8 Z/ R- j T public static void main(String[] args)
0 c m+ @1 [- g: E {
) b4 W: c6 ?, ` for(int i = 1 ; i< 10 ; i++){; i- o: s& n6 V
for(int j = 1 ; j <10 ; j++)
5 t, K. i2 l* \ System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
* D% x, j) b3 B( u, G- `3 | System.out.println();$ L/ R. s& i* `' E
}) Z$ S# |( @3 W z2 }: W
}& F& k, ^% A4 y( Q% |( d
}' G; ^( L1 o- m b* P. a0 z
7 ?" F3 \0 G' ^0 f
" g- a% j2 T7 y; GTQC109
, \1 R% t. O, m: q% h8 U$ ?% H! M: Qpublic class TQC109 {
6 r! q0 P0 C { public static void main(String args[]) {, ?! s$ i v9 R
int r;
3 P9 K, y) T0 t" x: q8 e% }+ w r=(int)(Math.random()*100+1);
# ?# k3 E# H8 R' `- _ double area = r*r*Math.PI;% x" `! J5 z' d0 M9 x
double vol = r*r*r*Math.PI*43;
) n0 Q6 z! T" v+ h* C1 k System.out.println( "隨機產生的半徑為:" + r );3 v1 k5 I' L6 c" S2 G( W
System.out.println( "計算後,直徑為:" + (2*r) );9 T& y# z" }6 g( A' O6 z% K
System.out.println( "計算後,圓面積為:" + area );8 H" h: k9 n4 ~1 y5 r+ E
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
^" ?; e8 b% g! u System.out.println( "計算後,圓體積為:" + vol );
- j0 \# F4 J* h! ?8 O$ W' J o System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
1 [6 _6 x" l9 z. W5 o( {. ?' ^ }
X' N; b" P, i}
9 r- w0 D& K4 W0 X6 n
2 F! b; O2 U, T* E& I. [2 ?( I" I % n7 m7 M+ q2 O- p: ], X
TQC110
4 E. C. c6 _: F8 Jimport java.io.*;
) Z! ~* k" j8 k1 o0 K" fimport java.util.Date;4 I8 i0 ^% e1 ^# Q; u
! E4 ~; B j& k) q
class TQC110{3 M8 o9 ~% X( C$ d/ f
String items[][];
3 A# b" X4 q) ?% a) ^ long start, end;
1 L: H- o, N4 `% Y Date d;' q# O; d3 b' o( D
BufferedReader br;4 N$ u/ L) i) f6 w- A( M; e
4 Y8 c! k7 s" u, ~% E4 M2 [ public static void main(String args[]){
: C0 b9 L& k# t/ x! { int total = args.length;) _# o5 a! D5 j# V
int pairs = total / 2;5 w$ M5 f+ v C9 F8 H
TQC110 tte;
! U1 y$ Y" U0 O3 O" m- @ if(total != 0 && pairs != 0)
7 k1 z9 d4 w7 t e* ~2 K* B: Y {" w1 g* R3 C$ q5 q5 C f! _
//get value from args..3 N7 H6 l/ g& a5 H% t
String[][] tt = new String[pairs][2];
$ U3 O: W% w8 d; p- i( n for(int i=0; i<pairs; i+=2){! i' l& t# J2 N) R! F
tt[i][0] = args[i];
3 [% Q- r, j. [/ S! p1 q6 F- O9 W tt[i][1] = args[i+1];' z5 F# k6 R2 n( e3 y; |
}
' H5 @2 ~" p$ v& S* H) u tte = new TQC110(tt);
~& b, U3 I A7 k- j }else$ ~, V9 z U$ q! ?. @' Y/ h
tte = new TQC110();7 o, D) _2 l9 b8 k! |; _& p
tte.start();$ t5 n0 ]( ^4 g
}, F$ {# x* J" r
7 C- X6 {9 c0 j+ _1 h$ ~& t1 D
TQC110(){
+ C- ?5 ^$ d3 j& U+ ~- c items = new String[5][2];
. i* X2 D1 G# T items[0][0] = "電腦";* R3 x7 Y! P' d5 Z3 I4 s
items[0][1] = "computer";+ d8 H s! ]- W: d( K
items[1][0] = "資料庫";+ h% m2 }- J, `5 }
items[1][1] = "database";/ ~7 v+ C, K2 i6 t' }; H
items[2][0] = "語法";
4 h+ ?$ {4 f5 @, Y7 l items[2][1] = "syntax";
" E& l5 e# q6 T- ?+ | items[3][0] = "學校";
p4 F& o, S, y' u' o items[3][1] = "school";4 s0 C/ g' |4 w( X+ c5 p* l. d- ~
items[4][0] = "假期";
; U! |. D( [# j# r$ r3 O) j; g items[4][1] = "vacation";: z. T0 V g, m6 u9 r2 a5 H/ {
//make default value
4 G8 @4 {+ T' n! r- x7 R br = new BufferedReader(new InputStreamReader(System.in));
) I" s0 f: H! \2 a6 c }# L9 f) r2 D) x
\9 h, s: x$ H& F
TQC110(String[][] it){2 r- g R! ]) ^
items = it;
3 a: O/ D+ t& G br = new BufferedReader(new InputStreamReader(System.in));9 \3 t7 J6 q3 x7 U) c' j0 j
}
7 F9 R& R' l4 \# T: ^" l8 \' i
* |" c# I( b& l' [ void start(){
. l# H% v; ~5 ~ String ans = "";
; m" o1 K4 n% M int correct = 0; // 計算答對題數4 ]5 ^- G; p# t# C: Z4 ]
d = new Date();
* {+ b+ G# z" K) O0 M4 b; a' o9 \ start = d.getTime(); // 開始答題時間1 H9 b" m( I# [, r, g1 W G
System.out.println("請將題目的中文詞彙翻譯成英文單字!");$ W6 C$ ^4 \8 q! y
System.out.println("輸入英文單字答案後請按Enter鍵:");" J: U, Y2 ~7 r* |
System.out.println(" ");/ {9 }- l4 v s4 F5 y
for(int j = 0; j < items.length ; j++)/ |, _- K. o2 T2 Y
{- J4 i- |7 L k' P3 E
System.out.println("第" + (j + 1) + "題__ " + items[j][0]);* ]: }, _( J/ w! m, @/ c) I) x( i
try{" `% u# v# p; y( W0 I0 N
ans = br.readLine();8 \- x- p6 Q" X( f0 h4 b1 ]0 D
}) z) I* ?4 F( |4 b6 L
catch(IOException ioexception){4 C7 B+ D5 o# U ]% i
System.out.println(ioexception);2 f/ I7 I! {8 v
}
% `( m1 N- L4 N+ H if(ans.equalsIgnoreCase(items[j][1])){
( J% F# I, ?# P4 p; h correct+=1;0 d+ h& k6 f8 ~# _+ w
System.out.println("答對了!");
2 B- N( e& M) \' ]) G g //count correct$ i, F5 \- J9 z8 W
//ouput correct message0 V' [9 r; u, p% L: y+ a% w' ~
}else{
/ [- Z, ~* d2 C1 [- v System.out.println("答錯了! 正確答案是:" + items[j][1]);
% R# T2 }4 O" ]# n" D' x //ouput incorrect message
9 l( d$ T+ M, H/ F4 z' @" d" B }
" _* E' a3 A% B! V( I$ p }, Z0 i c4 r6 G4 z
% Y4 L0 F' H( m: Y8 O* p d = new Date();" ]; ?' K- R7 E0 I% T
end = d.getTime(); // 結束答題時間, ~7 V* J9 Q; r/ z& g" ^3 k0 m. [
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");' \) q$ m; W0 m7 P* r% s* U
System.out.println(items.length + "題中答對了" + correct + "題");
5 Q$ D, R& m( P; R( u+ t5 { }, H9 r: E. D( u' b3 k4 E
} |