TQC107
2 b2 U3 Y$ a3 k; Qpublic class test{2 o0 f! Y2 Y) C
0 I4 |! x! ]9 b: w) S/ s public static void main(String args[]){
! l4 q. ^& m- u+ ^ - e- E; `6 E, N W0 J
//0 1 2 3
0 |. W$ X0 X3 g3 ?$ K //1 1 2 3. w$ R, L) i' S% a
//2 1 2 3' l# f& } g5 E: w: k3 ]
$ X: e' m; O: t( H3 {1 B
float tot = 0 ;) D$ v- P0 g9 N
for(int i=1;i<args.length;i++){
$ h/ P2 k0 a" R tot += Float.parseFloat(args[i]);, S1 }, S. @) p
}7 b9 s6 [1 a- S
tot /= (args.length-1) ;
9 y$ I5 Z% r* c/ [0 B 7 Z& F0 f! ]* ]. k
if(args[0].equals("0")){
) |1 d. H8 q% s$ } System.out.printf("平均值:%f",tot);: m8 R( x+ b* x: P( _! N: {
}else if(args[0].equals("1")){
g0 y, m: c( ~6 y/ S* o System.out.printf("平均值:%.1f",tot);
+ k1 V/ ?1 x% o2 i- u8 B. d }else{
$ @+ m. L Z2 |0 m- @7 F& V: ^. x System.out.printf("平均值:%.2f",tot);
7 o( w+ ], Z1 o# g' `* \: M" @3 j }
, E, ?, @0 ]5 S
" o' H3 d( h5 ~7 V
) a( c1 G) s" \9 j) W4 \ }% S) P9 {: S: F% n, ~& o. _
& @ Y, j% s: Q$ n
( ?. P0 G+ V# \: u
}
6 B6 Y# @$ V- K' p3 y1 sTQC1086 n0 `3 n6 |( U( O: W. z
import java.lang.*;
# ?3 Q5 O0 F/ { K7 x: W* c4 I% }3 R. v F2 u( [
public class TQC108
& Y# S. ^1 ^1 x" F{0 c- y+ y; \" {$ O2 f; L% U
public static void main(String[] args)
# r- {& Q4 D) M8 v8 j- l) G {/ i1 N# F$ |! z
for(int i = 1 ; i< 10 ; i++){
" u6 Z8 I9 |, k& B; |) I/ n2 F. F for(int j = 1 ; j <10 ; j++)
" e. h7 a4 @( `% R* ~, Z7 s% p System.out.print(""+i+"*"+j+"="+(i*j)+"\t");/ q+ T( v6 V+ R2 l' n4 \$ i
System.out.println();0 T. g; ^. h* r' D4 l" x
}5 P# u8 g9 T4 H; W4 Y% m6 Y) T
}) A! }3 C f- R# o8 e p. B/ q; _1 j) V
}
" F7 j3 B, k! `' p! A* b
' H9 I4 K. [! \, |1 d
; E7 Y2 E# F6 P/ JTQC109" U2 C2 J2 A2 g
public class TQC109 { E& v6 N. t' b! ^7 j6 A+ v6 F7 w
public static void main(String args[]) {
' ]" n8 ]) N/ | int r;) m' K. `: z$ K: b/ _- ]
r=(int)(Math.random()*100+1);
) I+ ]7 }3 d+ v( N. }; s$ L5 ` double area = r*r*Math.PI;
3 Y: H. ~) Z/ r( }% m' M- k* Q double vol = r*r*r*Math.PI*43;$ D2 {) [* E2 [) ~ B) q+ J! f
System.out.println( "隨機產生的半徑為:" + r );
3 T+ C, K* `. B$ i: N System.out.println( "計算後,直徑為:" + (2*r) );
( U0 F$ @0 u- r3 y System.out.println( "計算後,圓面積為:" + area );
) c' K# y# g( F1 G5 w; j- @9 H System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);; P9 V( L0 \5 {9 `7 w
System.out.println( "計算後,圓體積為:" + vol );8 ?) M( D( ~/ Z3 {4 i& R7 R
System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);6 S, r* P/ ^: g" u- v
}' o% U% T. o( T9 x' T. g( B
}$ b1 {8 t+ _% `
, r/ M8 h' `) W
: n. A) `1 R$ U8 D( h; f: q; PTQC110
5 O$ `8 e; r. Z) y) K4 o5 N eimport java.io.*;5 m0 q* e7 F* Y, c, ?
import java.util.Date;, D8 {4 h# `8 H9 l9 _
, p) O, Q+ ]5 x; C class TQC110{5 ~6 U% Y$ k6 O1 _( h/ {
String items[][];! d6 x4 c; q& f& ~5 s1 Q2 ^
long start, end;
3 b3 j& n4 r+ e6 _7 O/ z+ ]$ @ Date d;
2 t) a2 t+ s8 e% ^% K8 ^ BufferedReader br;5 X0 j. u% h& q, [/ c" `* K
" u; w/ ]: x% { public static void main(String args[]){
8 H. ~. |" ]+ y# G int total = args.length;
+ \) r6 L! y6 r int pairs = total / 2; V8 x% L5 k6 V2 s0 {4 `& q# \
TQC110 tte;- y9 R) |" B* @9 j0 A
if(total != 0 && pairs != 0)
6 X0 ?% u, g9 ?# L, E; y {8 J6 z- F* n. k# _# [# X3 h- I
//get value from args..
?# t) `) u8 _+ u String[][] tt = new String[pairs][2];
R2 G2 E4 ?6 e* q! @ for(int i=0; i<pairs; i+=2){, a4 P: M% ^* F) V. _
tt[i][0] = args[i];
1 Y1 k2 S# `. |& I' T tt[i][1] = args[i+1];
$ w$ f5 P" B* Q; [" U; s# u( [# ^ }) w2 h5 @+ B% v, c" c
tte = new TQC110(tt);6 }% @. s; U( y5 C! G
}else- [& C9 K i* n# n
tte = new TQC110();
3 ]. q) u4 R5 ?1 k) j tte.start();
+ h5 @& N I: o; V2 q4 v }: b, g z& W4 N1 Z+ D9 E8 }( @
4 C- t& r1 C9 @! }5 ^
TQC110(){/ \9 f% w1 A/ A' q8 \8 v
items = new String[5][2];
/ X; D! a" d1 Z4 p8 |1 O+ O" k2 H. v items[0][0] = "電腦";* K0 \7 C o; V! H [2 M! ~
items[0][1] = "computer";
1 T, M# {6 u2 O' M! Q1 o items[1][0] = "資料庫"; N P8 B% S K. c
items[1][1] = "database";" i M+ V3 b2 |) w4 Z. k- |
items[2][0] = "語法";
, T6 b, u& J: ~8 H9 l items[2][1] = "syntax";+ H" e9 l' s: @ }2 z. V
items[3][0] = "學校";
& ?1 h( b1 B! s, e items[3][1] = "school";
7 p7 j7 F1 c2 c& V3 W items[4][0] = "假期";
" S' u* ^! C. b/ {( R items[4][1] = "vacation";
; T- ]& |7 W% u! r5 N //make default value
, j1 M5 Y T: g1 V5 h br = new BufferedReader(new InputStreamReader(System.in));
: Q9 u( J) k" ]4 O9 l) a }: C. c1 \" o9 w
% J* N4 w+ o1 p* d$ f3 O- E# c/ Z3 K3 K TQC110(String[][] it){
% @1 t' w+ z8 {& l- B$ \ items = it;& Z& u" }2 U0 ~; U
br = new BufferedReader(new InputStreamReader(System.in));
1 C& P. Z/ s6 E3 i/ ? }3 g. a. C" }; G$ J
! R: q; m: ~: Y1 {+ t! W1 B void start(){$ ]8 v! R) Q7 b
String ans = "";
n& u. f7 F: h, ` int correct = 0; // 計算答對題數" c- Y k0 v: N3 z2 n/ B; \
d = new Date();
B0 ~2 U F7 I0 [: v start = d.getTime(); // 開始答題時間9 ^: L/ k- g% c6 ~
System.out.println("請將題目的中文詞彙翻譯成英文單字!");
( l o) u7 C* R System.out.println("輸入英文單字答案後請按Enter鍵:");
; \# R6 E4 Y$ Y, i" |% q8 l# i System.out.println(" ");
1 R6 t0 w9 k* z) [/ ^8 K+ I for(int j = 0; j < items.length ; j++)9 k5 B' ~" w& Y0 C( {
{: |4 A! ~) a: \, U2 Z8 C
System.out.println("第" + (j + 1) + "題__ " + items[j][0]);+ \2 s* d7 \# \6 ?
try{
8 O5 S a5 q, n% M ans = br.readLine();9 x( j& V! P% U A2 M* m
}
5 t8 |# I1 E, o+ @0 k$ A catch(IOException ioexception){
: V# F( M! T$ x& g3 ~( Z7 q System.out.println(ioexception);# ^1 Z/ \# Z- x0 ~3 R9 v) U$ h
}
& |+ a$ P4 k; h+ L. I- T if(ans.equalsIgnoreCase(items[j][1])){
. M5 Y8 x) ^! U) j correct+=1;
8 f, R$ d6 H$ ^. | System.out.println("答對了!");! j' q1 ?# U% t9 C$ u/ n# y7 m
//count correct
( r. h, |/ E- Y8 W7 p# r( o //ouput correct message
; Y1 |( d( F$ a0 K& B }else{
- M0 H4 M; F: t/ k2 T System.out.println("答錯了! 正確答案是:" + items[j][1]);) @! s/ N% G) G( K" ~
//ouput incorrect message
. L1 ^. B$ A, D8 _! S } O) k" X8 |6 ~7 N: |$ t% f
}, B4 ^0 y& d- H+ o1 ?8 ?
2 A5 K p: i$ }9 c
d = new Date();
5 J! V9 C9 O7 _5 Y+ S+ ? end = d.getTime(); // 結束答題時間" m* v! \; T# _% j+ B
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");
* S% S0 D& K) a' X& [* K System.out.println(items.length + "題中答對了" + correct + "題");
! l5 m4 l. ^3 P! f& I5 C }
3 j3 U9 S6 O/ g" H% c3 i } |