TQC107
* X( v. ~4 X' J/ {5 P4 i2 ipublic class test{# s3 p8 r% G5 l: y; \
2 ]4 D3 Z0 u, N: }0 g3 g public static void main(String args[]){
x R/ ^0 b+ P& p O+ { ; N2 ?& |, c& \4 S" k- ~7 Q8 R% }
//0 1 2 3
3 y" y8 L: }+ w //1 1 2 38 m m C7 W4 C( ]# l0 r# G
//2 1 2 3 L% l$ E& r: I( i: O: e
4 b3 h7 B, z2 ^3 @: f- A) m float tot = 0 ;9 w# ^7 k! A& K* c; e% @
for(int i=1;i<args.length;i++){2 F/ [& h. q" E7 J9 h, b/ C
tot += Float.parseFloat(args[i]);
$ I# p' y( f; ]* s }
' ^- N% C( g3 o: [3 s9 ^& U tot /= (args.length-1) ;
, D4 E- d5 y- U' [, Q 0 d# \! `+ i, w% N6 _+ M
if(args[0].equals("0")){8 I' p' q" g' ]2 g' t8 K7 V
System.out.printf("平均值:%f",tot);
# U4 q% `1 a \/ d }else if(args[0].equals("1")){- ]+ b( E0 k$ e9 u
System.out.printf("平均值:%.1f",tot);; {( B: u1 A2 R" ~
}else{
5 H5 L1 t. s* Z0 Z* d. y' J- i/ l1 t System.out.printf("平均值:%.2f",tot);* l" g" ]& b1 W. I8 P2 Y
}
$ _: N/ w l! R/ G4 B+ V, M ' x2 N" L6 w; k% W
8 e# g' J' Q8 F3 a9 ? }/ `( }$ L$ x1 P. E" M2 ~" F
1 M% Z9 F6 h! `4 { `4 r* I& P2 b
6 `1 d2 v# u& E/ w6 G1 y3 K C}
* ] U' B2 G Z8 ]; DTQC108+ }- T o$ p0 n0 F
import java.lang.*; b4 i5 E* l8 z& Q z
4 L7 A1 ?1 k( I
public class TQC108" g: h8 O2 p; y
{
8 z4 X' t/ s: s! Y+ m0 C public static void main(String[] args) 2 E! F- N5 H4 C) x2 G9 o$ n" I" `
{
7 x$ Q7 u, E7 z* X4 H for(int i = 1 ; i< 10 ; i++){ V3 X8 r* z- [
for(int j = 1 ; j <10 ; j++)
: G1 t% Y. O& o' w System.out.print(""+i+"*"+j+"="+(i*j)+"\t");6 Y3 g1 {: ~4 p, F k6 Y/ j
System.out.println();
~- b% s3 S" Z* x/ ]: F5 V }4 q+ E3 C+ j+ P( I* l2 W
}5 x0 C2 v8 O; Y$ w, G4 Y. j; @
}2 E- G- n$ F, s- E0 U, @
, C1 ~! Q- x$ y# `
1 x; k+ U, e+ TTQC109
8 Q5 A) V7 \# a% a- n C" C. S6 \public class TQC109 {0 ?6 @/ u Q3 w" g
public static void main(String args[]) {' Z5 `4 Q0 p* I; b' T6 Q
int r;
/ [+ F, T4 C6 l# H* o r=(int)(Math.random()*100+1);
1 D8 L( k, Z) |/ Q double area = r*r*Math.PI;! X/ a& w6 D( A
double vol = r*r*r*Math.PI*43;% D% D8 C/ Z, y& Z& B+ N
System.out.println( "隨機產生的半徑為:" + r );
" c4 F U) T0 s+ H* V System.out.println( "計算後,直徑為:" + (2*r) );# d u7 o! l& ]( T- a8 a1 @. c& r2 T
System.out.println( "計算後,圓面積為:" + area );
0 @( ?8 |9 ^# \9 d+ g$ C. m System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);7 t1 g, @" A# Z
System.out.println( "計算後,圓體積為:" + vol );
4 @4 r; L8 u d4 u) D% ^ System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
8 W" |/ R& d, K3 ~4 h }
; q. e& G0 Y* K" K7 a0 K" z}
, X o5 @0 m3 i2 ~) O9 p) b: k" F7 h( L( U3 z
; O) G; v$ T6 x" o0 H! [; | M0 xTQC110
6 j7 K7 ?+ ^( x1 b3 {; Y' x7 c' oimport java.io.*;& M1 g% N! @! n; T/ u
import java.util.Date;8 W, |) k$ Q# w- }7 P3 l0 m; h+ U
5 \+ A) f* X3 ~ class TQC110{* c0 f9 P; W9 ]7 d* P! f T
String items[][];
. q( p1 y4 _; q# X! F long start, end;
8 V) s2 t, O" ^" g& f$ r Date d;; a& C/ j4 Z9 B" @* k
BufferedReader br;
4 X; i1 p5 L) r3 `% e6 e5 z6 p
8 r( F0 ^$ W4 O8 @2 }. i public static void main(String args[]){
9 b! e+ ] a* t; Y* E: s/ ] int total = args.length;8 j! h+ F. r1 E/ q
int pairs = total / 2;) O9 ^* e3 C# e- w8 Q
TQC110 tte;
1 q( u) l8 r' J E if(total != 0 && pairs != 0) x) R# e# P( A- l( Y
{2 N7 X$ ^" a. |7 c4 Z
//get value from args..- O' F9 N& j) @4 Y; [
String[][] tt = new String[pairs][2];
/ ~: Z6 M4 F1 u for(int i=0; i<pairs; i+=2){8 a- V) U% j# M5 |. B# k, v/ T
tt[i][0] = args[i];
6 g5 m' E9 j6 Y1 L4 A tt[i][1] = args[i+1];# B$ h# t& p- U: x/ i5 U
}* l" @$ T* Z. l8 L# o9 C( m) q
tte = new TQC110(tt);; d+ p% h: [/ K" Q o8 t d
}else
+ \3 }- E( W2 k7 }: O3 M tte = new TQC110();& U- h' P. g# F& k' _
tte.start();# k) f x' z% X
}
2 w! ~2 l. b5 d# U: N% ]! |) |6 b& [+ g0 G! P! b. Y
TQC110(){: F4 A$ q8 N& b, p3 Q
items = new String[5][2];
4 g _" x# J. e8 ?3 X3 `8 s3 ] items[0][0] = "電腦";* q$ m& B' \3 ?$ X: ^- c% ~
items[0][1] = "computer";" j( ~2 k# r8 y0 P, I
items[1][0] = "資料庫";
+ E$ G: g5 b1 k* W* L+ ~ items[1][1] = "database";' z: p0 B" ^# ^5 V+ J% |
items[2][0] = "語法";
# Q$ z( u/ q! g* R items[2][1] = "syntax";
1 D+ l e) d- @* }$ [& J# X items[3][0] = "學校";& q5 i5 h: u u) X6 ^; q6 ]
items[3][1] = "school";
2 s$ ~+ B) E4 [$ o items[4][0] = "假期";# A3 x0 e& O3 v
items[4][1] = "vacation";
# C% i6 F/ I0 e4 A |8 Q: F+ f //make default value
. b4 x. s; w; }( K R/ K br = new BufferedReader(new InputStreamReader(System.in));
8 _$ M# Z0 q5 E7 g B% e+ |7 Q" _ }
1 l$ N/ _. V1 W6 s/ E$ S5 j " i3 Q! c; \" {) w7 L4 g: ~
TQC110(String[][] it){
* H0 M2 a+ L$ E4 B. c items = it;. m' f7 u0 f9 R, K* W* u$ I1 g( l
br = new BufferedReader(new InputStreamReader(System.in));' ~0 h' p! | T+ v* [ ]
}) R/ M; S$ b1 g( e/ K
5 m# ], K T) S7 c8 n void start(){
& @1 G! ?( n0 d- L. b! C) W String ans = "";
1 t) i5 O: S, K8 n8 L% f3 J8 p- `' Z int correct = 0; // 計算答對題數, t" q! ?% O5 g
d = new Date();
7 A- J4 z+ Y' G1 I& J start = d.getTime(); // 開始答題時間- C4 I+ D5 i' ]/ z1 f7 g9 s; }7 d2 e
System.out.println("請將題目的中文詞彙翻譯成英文單字!");& g1 O" C7 e* f9 H% B1 V2 d
System.out.println("輸入英文單字答案後請按Enter鍵:");0 g* d+ d6 t) W7 ]% O) H
System.out.println(" ");
1 N4 m) r/ Y- R1 I4 ] for(int j = 0; j < items.length ; j++)8 K5 J. u; v( r0 n/ @2 c/ `% B
{
# X* v8 G5 q p9 I: \ System.out.println("第" + (j + 1) + "題__ " + items[j][0]);/ `- U: `' ^' [) `
try{
3 o+ y4 g' C, X+ j6 ]& N ans = br.readLine();
1 _4 z2 d ]+ d" k) ~9 x) x6 q6 y }/ P. k/ R! ]0 K. ~( t& G( `: _" h9 L
catch(IOException ioexception){
( T1 S$ B1 T) q% K& R" N+ v& y, `8 k System.out.println(ioexception);
+ K$ e/ c% f6 P" \& F5 F* @: Q1 v2 x# d }
( Q, `8 j; k% h( A$ j if(ans.equalsIgnoreCase(items[j][1])){
. w! M/ d- h5 N! ]/ B1 K, m) m correct+=1;& H$ q7 z5 ?+ W, @
System.out.println("答對了!");, U9 l3 q6 J4 w0 \* m( P
//count correct3 [) i& h0 ]: X- H, T
//ouput correct message
3 M W) d% f9 u; A3 r }else{2 o5 _6 a2 J3 X% T
System.out.println("答錯了! 正確答案是:" + items[j][1]);6 V; L5 y7 j0 k0 s' F
//ouput incorrect message( T# \$ [$ z- d6 ]2 ]* W& P7 t
}
+ A: }% L+ o* r: p: a }" E( g5 q. c) w. b5 s F: V5 |
5 @4 L* d1 ]) j: v" \9 x+ Z0 o' r; p
d = new Date();: U0 X/ n, p' B! T8 X' m
end = d.getTime(); // 結束答題時間
* B. x& Z5 ?6 S, o S* ~3 M System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");4 c5 F- m. L L, e
System.out.println(items.length + "題中答對了" + correct + "題");3 F4 f9 @' N& H; H6 C" J" Z
}
0 }, g1 @$ M& P7 C1 s4 `' j } |