TQC107
0 d9 o2 W3 g! |. ~1 ~public class test{
! J, E8 x; J% k
1 K) ^, y8 @% ~1 P: K& G, K public static void main(String args[]){
& y) ~0 R, ]3 ?5 {4 O3 R$ F3 Z $ N" J: M- ~2 [1 F" G
//0 1 2 3 , {* ^; v' n- u7 K+ u: z, h
//1 1 2 3
3 q' Z: V5 W3 E: [. \* q/ b( ? //2 1 2 3
4 l2 y# N) a8 y3 D& z
$ x% v l: n. I: v! J float tot = 0 ;
5 x3 U7 D9 \8 M' c2 T. j3 h for(int i=1;i<args.length;i++){
5 T3 X6 [# v( m* Q tot += Float.parseFloat(args[i]);
q- i( @* s7 `6 r6 N. l }( @; w& u. g! F3 O
tot /= (args.length-1) ;1 C) T F( k A0 S
3 a6 f) _! @1 ]1 S' A2 i. Z if(args[0].equals("0")){
: \9 R4 i# E- D& W7 b& {1 v3 @* M System.out.printf("平均值:%f",tot);
" V+ _/ @+ f V2 r5 z }else if(args[0].equals("1")){; Q, F# {5 N" W$ Y) C" C4 m; @
System.out.printf("平均值:%.1f",tot);
: A+ m4 c+ `! K: k! U$ P5 G* E }else{
, s/ P, k, w; L4 v/ z' Y System.out.printf("平均值:%.2f",tot);
+ h* ]( b; p1 @9 d, L! { }9 K" u& d# _* A, I0 d
- Z) r* j. u' g5 V
! d% @- h: c+ o x7 \6 v }
" {. U: a5 f, v) n F* _, U' g' L* |. m
3 j$ U3 s& k$ m* t( Y, h. `. z
}
5 \' g- w" I i; \1 Y1 R4 DTQC108
% L, p0 d- V2 g' x) k% }! Wimport java.lang.*;5 z! s4 {- ]+ H& W- l
$ p V% r% _ @; f/ _$ x5 `- {public class TQC108
2 K- N! _$ Z4 @ j, `{
# |/ |' ^- T/ J8 E, X7 T( x% n# N public static void main(String[] args)
4 u% A" M9 G% T7 I/ z* ? {* Y1 a- x4 s+ |; ^9 O( r+ S
for(int i = 1 ; i< 10 ; i++){5 ~4 N0 \ x: @/ V( m, r7 Z4 n- ~
for(int j = 1 ; j <10 ; j++)
* L9 \! P! y, ^' Z4 }+ }( |8 I& a5 ] System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
3 w" I3 ]9 g8 j: f& d& f System.out.println();
) A. j: i" c. E' o8 S/ q' m0 d3 ` }
' N: L8 Y' x4 E$ ?) U% e }
' D2 o( Y, A2 x4 x8 ]# J; P8 k}
& D) x2 r( v9 A1 Z6 ?
: E& @; e9 x, {1 \
/ `5 J: _( E4 _6 VTQC109
' ^( k B6 b; H9 q* n0 C" M" ?# Mpublic class TQC109 {
6 W! D- i/ A, g, G c& {2 O public static void main(String args[]) {& e- f' S: y, q c
int r;+ r2 P7 |5 x1 E' q
r=(int)(Math.random()*100+1);
' b- `# F8 }7 c9 ]9 d0 D double area = r*r*Math.PI;' N- I2 K d$ Q) K( R9 C
double vol = r*r*r*Math.PI*43;
1 G4 D g) ]1 p3 Z# U% B System.out.println( "隨機產生的半徑為:" + r );3 }; H! m7 R, H$ L. @* A: `
System.out.println( "計算後,直徑為:" + (2*r) );% p' r; P9 V' f! x
System.out.println( "計算後,圓面積為:" + area );
: d0 N; i( t9 r2 w$ v& G* x System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
7 E- |, S. F2 B" h; s System.out.println( "計算後,圓體積為:" + vol );
' _7 _5 _- u6 Q8 X System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol); l T6 b/ g9 W V$ y4 o0 I9 I
}
. S: L! W' x5 z7 }/ v9 l, ~- ~6 E}
$ z1 v8 U1 Y/ F0 }2 b6 A1 f# ~9 h
0 |( l7 r9 u) Y* Z( X& wTQC110
; z2 d }# X t) P2 t; n: O' simport java.io.*;0 ~( M# G: L* h- ?: P
import java.util.Date;
U. m, w }: P+ ~, @$ l' Y
: H @! l; J: v! I0 N/ E$ S class TQC110{
6 ~; _7 Y' w2 O# W7 ? String items[][];# h$ \* r5 p! s( W6 i1 P
long start, end;
' ^! h( D1 q% n Date d;+ R i6 I% Y6 v: o6 k0 |
BufferedReader br;
, s9 f$ l6 M b& i2 h
0 O3 J D- o% Y' ]. g& W public static void main(String args[]){
7 z2 |0 q4 g# j int total = args.length;
1 m y/ n! Y$ r: N# D, \/ o2 O1 m" V int pairs = total / 2;2 G u6 j! u, r% s
TQC110 tte;. e8 \) \/ f" k' k
if(total != 0 && pairs != 0)1 H4 x1 r- Q) F+ B) H
{
0 O* z0 q5 _& L- _* B //get value from args..
5 {/ }, p( [# g% {8 j( i# a String[][] tt = new String[pairs][2];
# O) H5 c1 M: a2 ]" s' p for(int i=0; i<pairs; i+=2){
2 ~7 {3 V" C; w- z tt[i][0] = args[i];; r9 Z2 P% c) |: G
tt[i][1] = args[i+1];
6 b$ h% e+ Y9 T6 R3 } }
9 r/ T. q5 p9 P& o( W% c# E tte = new TQC110(tt);0 q. K+ A; n9 X+ F8 N
}else! o& @% V6 r3 X2 n
tte = new TQC110();# N$ ~- n+ w& n# Y1 b+ l
tte.start();1 [- w o0 D, L# v$ w" D+ T
}. w7 ~: w9 F$ ^8 T2 j
4 o( D8 D2 t( l N4 ]" W5 u
TQC110(){" ~9 i3 f* R! e* J
items = new String[5][2];
g, d. ^- z. E" U+ r4 G; M$ [ u items[0][0] = "電腦";) x }( G% U: A9 g( ?0 _
items[0][1] = "computer";
3 D I5 b8 e# \! c items[1][0] = "資料庫";
8 N3 q4 C. N6 h. A items[1][1] = "database";
0 E3 c0 u9 U& Z2 q; \" N, n items[2][0] = "語法";- a. j) D, \0 F- x1 Z& G
items[2][1] = "syntax";
0 B }9 }5 n3 L2 C3 @ items[3][0] = "學校";
1 t7 e2 J& A, z9 R6 T" l items[3][1] = "school";( g$ r/ ]- P) M% a
items[4][0] = "假期";6 V; e( o+ P( p+ y8 b
items[4][1] = "vacation";! |, \! p2 u' R) ^; v
//make default value
) _5 I: c! a! \6 F* b( k br = new BufferedReader(new InputStreamReader(System.in));2 p; L8 K+ @3 I$ w; p: w
}
# s. a: v8 V* i& f- |. z) K ) O. r& i$ G. S* d
TQC110(String[][] it){4 _) C+ t( x$ S \5 }
items = it;# Y2 @& e; }5 v$ B2 p
br = new BufferedReader(new InputStreamReader(System.in));
/ i$ n9 D- h( |2 z- |' U& }. f I }: }7 x _! i4 B4 L1 E! h/ `; k
) P" U% y. W% \: N9 m8 ]" Q; e void start(){5 Q$ d6 j2 c3 j* N: @; J& l. e
String ans = "";; w% L9 J, p; s9 ] h
int correct = 0; // 計算答對題數
$ c: Y& k) r! _# q8 _ d = new Date();
* P) K5 g2 }9 G+ K+ c' B start = d.getTime(); // 開始答題時間
2 r5 A- |( R! T6 l( n! h6 v System.out.println("請將題目的中文詞彙翻譯成英文單字!");
+ K7 a% m. I; L( r' [9 h6 j System.out.println("輸入英文單字答案後請按Enter鍵:");
C& ^; m7 x) `5 Z/ S8 u! j% [ System.out.println(" ");
# K& @- V& _) R: U1 B r for(int j = 0; j < items.length ; j++)
8 U' D* z6 j; ?, y {
: f' z1 u& N0 m W3 ^% [8 o System.out.println("第" + (j + 1) + "題__ " + items[j][0]);. y9 n& x9 ]$ z$ x4 F, n
try{* m$ U! l- V' Y" x( z
ans = br.readLine();
6 {4 f' x& D0 y }1 P5 _6 Y6 f: Q: d; C) l6 J) r1 M
catch(IOException ioexception){
7 X" k$ | M6 H" X7 L& O# s System.out.println(ioexception);; [6 S& W: ?. ]6 ^
}9 E2 q: Y F: B* L9 v# v
if(ans.equalsIgnoreCase(items[j][1])){: N7 A# E$ z1 j. Z+ a! ?8 E4 ^
correct+=1;
9 h" b) I' \; s, p/ n+ B5 t System.out.println("答對了!");+ @; D" K. Z% z# X
//count correct9 _, d; G7 ]; s3 N$ u4 M
//ouput correct message
$ Y( c8 z# C- i6 `. R }else{/ I( X! u- a) i
System.out.println("答錯了! 正確答案是:" + items[j][1]);6 P! {. N, k; s8 n% T* x
//ouput incorrect message- |! V& Y# p6 b+ X+ H2 U0 P
}* Y! i2 r0 t9 z
}5 Y6 d5 o$ T# S" w I# g
( h/ C, p5 K b) \+ W; \
d = new Date();
7 T% Q5 V8 Z" s8 B! N& D3 z# r end = d.getTime(); // 結束答題時間( y* b7 _6 I: g
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");
0 O* \4 _: i& N6 C1 y System.out.println(items.length + "題中答對了" + correct + "題");2 d1 \8 z% J9 P, _9 g4 d* C
}
- l. k2 J+ Q2 f0 x } |