TQC107
5 N+ | `: \- n+ apublic class test{
) ?1 r7 `0 i; F% W6 f( Y& L/ {0 s! v; b; W. B% \/ M
public static void main(String args[]){3 t" q+ e8 ^9 Q9 E
$ T6 [ X% N2 Q9 X t+ y! k
//0 1 2 3 2 n* C% a" F2 V- H( Y' t) V, \
//1 1 2 37 _7 F6 q P" u- T; W- T
//2 1 2 3+ K& A* E+ V5 b9 T% L) t
1 j/ {+ P% w9 w! t! L Y
float tot = 0 ;1 D! F' V. G% q, F
for(int i=1;i<args.length;i++){
1 @+ S8 j/ P4 P/ E% s( L+ p# R tot += Float.parseFloat(args[i]);9 K8 A& X" E9 e6 W
}
6 [: Z1 y& E5 f" q; h$ A* N- F( F0 K* X+ { tot /= (args.length-1) ;/ [/ a- E b4 b
. H, `8 H7 h# J# R3 x8 j! I* t
if(args[0].equals("0")){
' j: E+ t: N& g/ e# J5 v! b- R System.out.printf("平均值:%f",tot);1 l8 k4 k9 |4 a* s. s% e
}else if(args[0].equals("1")){
5 w3 G7 \2 g5 R3 _" J& h" b System.out.printf("平均值:%.1f",tot);
8 W* Z7 G' l6 o1 n }else{9 e/ P8 T( a, V1 g* {( g
System.out.printf("平均值:%.2f",tot);
1 ]- ~9 g9 A4 |6 B* B% F2 G$ I+ X+ U }- [. z6 e6 f( k" C2 k! ~
1 D6 X J- J* I
2 E5 G( E+ }* d: w% a
}1 g5 f# v9 H2 Z$ [; f) F
% B7 A6 p" C$ g; Y7 |! Z
' ~# S( \/ j }) M}: A: C0 U+ J7 Y9 S5 M/ w _
TQC108( W- z! u3 r- q2 P5 G! y5 f
import java.lang.*;$ q2 c( p. N- c- _, E2 t
& N- d- l$ {1 s rpublic class TQC108
! x& g1 ~7 u! O0 _4 O{+ f4 K$ m4 ]* D8 y: ?$ s% T% y3 o; `: y
public static void main(String[] args)
: S; h, g/ L4 x# a# @' g. \" u" ?& q { C1 f% P# \( M8 n
for(int i = 1 ; i< 10 ; i++){; I% C( C; ~% ?7 [7 |
for(int j = 1 ; j <10 ; j++)7 O" [8 x! I5 [/ r2 U, k
System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
# c3 ?# Y& @7 b+ a, R& k System.out.println();! i; }5 u8 A2 c7 S, Z0 D
}
' L9 W6 t+ f* H4 V* { }
1 \! Y% y. S! D3 ?" `* t}
: p/ ]4 S: t! J2 q' W2 `, i4 `9 s% n# h! s& ~
, Y' v5 k2 n9 m$ P2 BTQC109
+ j) `5 x/ y5 R. Lpublic class TQC109 {
4 F9 `' o$ H7 B8 l' a. G" h public static void main(String args[]) {
+ D) e1 {; X& D6 T, M% V int r;
5 Y# d# Z! o/ j4 e. [. U r=(int)(Math.random()*100+1);
9 V3 @$ p: S; j# C% u double area = r*r*Math.PI;
, p" k+ y1 |2 g9 J) T double vol = r*r*r*Math.PI*43;
9 K: N& B7 }# o System.out.println( "隨機產生的半徑為:" + r );
8 h/ ]: W1 A* x2 [, ^- M9 a System.out.println( "計算後,直徑為:" + (2*r) );9 r$ W0 g0 k2 Y0 |; R: J
System.out.println( "計算後,圓面積為:" + area );: B1 g8 _, V# O5 x( p
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);1 _. r0 T9 k* [% @ }
System.out.println( "計算後,圓體積為:" + vol );
! L' Q6 U2 }' @9 F System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
! F" r' x7 D F* Y }1 b0 c* `9 C# p* Z
}! u% J2 e) G$ V+ S
& P# @ y& q1 M" z 6 k4 r7 C# h) u+ L9 q1 {
TQC110 ; o5 p- j' j( f1 \$ q: F
import java.io.*;
: K* [/ Q. b2 o: Dimport java.util.Date;1 ]! W! O+ a' ]( F- f$ e, q
& c1 Y8 Z# q' I
class TQC110{! f# b( r" P' K; T0 r
String items[][];
/ S L, E9 T$ j u/ H! @ long start, end;7 V7 v; U8 a2 e2 ^1 g
Date d;
. c/ a! U; Z& K& v3 \9 R; p' P BufferedReader br;
) @' R" w, B- M/ c' n- @/ j; o5 U) q: b9 E c7 z
public static void main(String args[]){
- t. F) `! H% N int total = args.length;- i) s0 e+ I( |; W+ a
int pairs = total / 2;- e" l+ y+ E- y4 @. g# D5 R3 N9 W" P* S
TQC110 tte;
7 X1 u! a; R( C! x, E' Q; P if(total != 0 && pairs != 0)
5 E7 \, U( V7 w5 ]. m9 F {! d4 O( z9 Q) i* l. e
//get value from args..
# H5 z6 J8 c' B& D- `1 p/ \. j+ G String[][] tt = new String[pairs][2];
# o/ c( w3 |# ^$ p4 F/ W for(int i=0; i<pairs; i+=2){4 s* A" J; R' c5 ?1 g
tt[i][0] = args[i];% i) X& \. ^6 {& t
tt[i][1] = args[i+1];
) A, |- U4 N. r9 C }' `: z. {) m- s+ _
tte = new TQC110(tt);+ H) i+ d0 f# o0 z+ {
}else
# t/ d& Z9 W! k6 [# ?9 m' H tte = new TQC110();
9 R1 u& P* O6 f' T2 S5 Z tte.start();
' @6 y% e( R& Q! K }5 @$ f) B( w# L" {" ^0 t2 A( f
S2 n' Z; f0 I$ R7 d s$ A
TQC110(){
3 _# @: w6 U3 w' ^4 L! a, } items = new String[5][2];
9 U9 R* @% O: O8 r+ G items[0][0] = "電腦";
6 M+ J7 w4 P' D! c/ A* K5 ~ items[0][1] = "computer";
7 \+ B, n" c6 t items[1][0] = "資料庫";
6 M% a4 l/ p4 W" c1 N3 t items[1][1] = "database";( M6 t" w9 U0 m: W4 @; [
items[2][0] = "語法";1 s! {. B$ y" j/ {& Q) W% L
items[2][1] = "syntax";5 E2 |0 f d" l& ]1 Q9 {' Y
items[3][0] = "學校";$ j: N( G- R- [$ Y3 U# V4 j
items[3][1] = "school";: O5 K2 a2 H% p
items[4][0] = "假期"; Z' M! g4 H5 _1 [! R$ R: a
items[4][1] = "vacation";
9 J" e Q9 ]4 |; `9 r2 a0 A //make default value
: m2 e3 u' E% Q7 w! i5 W br = new BufferedReader(new InputStreamReader(System.in));4 v/ [6 [% W% { b" a: u
}# }7 _: y$ ?/ |8 \) P: ?
8 e* v' S, F* }5 } e/ u TQC110(String[][] it){, v) E6 C6 A9 l" I3 g. c% B+ x
items = it;
0 f, x% b; u1 v- }/ K br = new BufferedReader(new InputStreamReader(System.in));/ ]$ J' i8 {' U$ y5 g" ~ C' d
} A/ j& _0 o/ Y3 q
6 G7 m2 n* G3 q% N6 ~- }% j! A) x% x void start(){( `! |2 f( c( x! s
String ans = "";( t* r- ^: V- k/ v
int correct = 0; // 計算答對題數) l$ M9 h1 V# i& X3 ]
d = new Date();; `( O# \4 x: ^) k& [9 |) ]; d+ s) W
start = d.getTime(); // 開始答題時間
7 g `& ~: N* T6 `6 ` System.out.println("請將題目的中文詞彙翻譯成英文單字!");
* `5 U; {9 H/ U6 p r: h System.out.println("輸入英文單字答案後請按Enter鍵:");
$ _. a# i+ Z9 O1 T2 _ System.out.println(" ");. |# j) ^7 z# X( C
for(int j = 0; j < items.length ; j++)* d7 h/ V$ V- _! O
{' g9 G5 R6 _* P. n4 x
System.out.println("第" + (j + 1) + "題__ " + items[j][0]);) o# C7 {" c$ e' x
try{
; V/ Z6 W3 L# Y4 i ans = br.readLine();0 w, `$ N6 G7 y7 I
}9 ]1 t$ ]( u) Z) ^
catch(IOException ioexception){
7 m6 l6 e' u+ R% ~ System.out.println(ioexception);
2 C) S. n) R) [: m }, N/ {- t0 n9 |' V4 {3 ]; U
if(ans.equalsIgnoreCase(items[j][1])){6 q; H5 u( l% A" Z& a5 U+ K/ ]* ]+ w
correct+=1;1 z- U& z7 z n0 i
System.out.println("答對了!");
! l" H& I. c2 p0 p2 Y" |" s2 h) v$ | //count correct; v+ _9 D+ E/ t/ h: B
//ouput correct message
9 p6 h; o! b: |0 b! }6 s3 P9 F }else{" _: r7 f: Z9 B J; ?2 R
System.out.println("答錯了! 正確答案是:" + items[j][1]);9 G4 B/ o s9 c: b7 T" c
//ouput incorrect message
3 e6 K* d7 n+ k+ N+ V* @ }
' Q0 o; a9 } z0 S3 k' X }
. Y0 w, u( g0 i$ A
' e+ g) H: n) X4 a d = new Date();# \ ^, J: k4 m* x
end = d.getTime(); // 結束答題時間$ \* [* r9 ?, r/ N
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");
2 J9 O h% j, s% Q Z System.out.println(items.length + "題中答對了" + correct + "題");! M6 }4 K# p. c( X2 z/ m
}
' o' t1 w7 y, o* H" G4 w } |