TQC107
2 y% \0 Y: | ~2 q8 |public class test{+ L4 y. ` H+ e& Z/ g \
; B, c5 i; N+ d! M$ E2 B$ B
public static void main(String args[]){
& T: v; v1 Y! h! @( g4 {7 k
# T3 Q, o" H* Y9 V6 l8 B //0 1 2 3 & u @" Y5 z/ h
//1 1 2 3
# D" R1 v# O3 V4 Q7 _ //2 1 2 3
& H5 R) |* G4 z; r * ?1 g( b2 U* H7 d, B7 C* e7 L
float tot = 0 ;) ^* S# f. Z, |
for(int i=1;i<args.length;i++){
( R9 ?7 _2 Z. t7 j+ V5 O tot += Float.parseFloat(args[i]); m6 q$ x0 W! [
}
+ }* {: S, I& c* u% y/ D tot /= (args.length-1) ;
$ l; f0 i. u5 [7 F A% U' t/ P" j
: m3 Y5 @ [) a* U4 m U5 l$ K if(args[0].equals("0")){
# L$ {5 `3 e/ S0 Q4 Y L! @& Y System.out.printf("平均值:%f",tot);) b N8 C7 ]1 _
}else if(args[0].equals("1")){ L& p3 `4 |; G/ R
System.out.printf("平均值:%.1f",tot);* v, T/ V2 x% U/ F7 f
}else{# H$ M+ O- M, V$ R4 l" M
System.out.printf("平均值:%.2f",tot);
: R- v+ e! G7 U7 k+ t }
* X# _, F7 a+ d8 M2 W! R% g 7 ]2 `0 a* W! @
' a1 {8 M7 S5 f; t, m5 t5 a- ?" N- X
}
# g6 M# |. h% S
' [; C0 n. P2 Q$ X4 v. ]3 Z) i6 o+ X. i" C1 H, L. J" b
}* S2 o( i0 n7 v1 v" i- M
TQC108
/ F9 G0 ~8 W1 [% ?. v8 d6 S4 _import java.lang.*;4 a) C9 |* Y/ ?9 i9 `: E
( p2 z, X- k5 o* H/ l" k0 U
public class TQC108+ ^+ M) |' V1 ?8 ]0 S
{; R0 ~# v! j0 I4 n; O& r
public static void main(String[] args)
. o$ K U4 }3 X {
9 r; e6 S7 i, }+ r# Y% L8 W for(int i = 1 ; i< 10 ; i++){8 n! g3 c8 u0 G/ [+ ~; Y5 N" C
for(int j = 1 ; j <10 ; j++)- s5 y. B2 T! _& k0 n
System.out.print(""+i+"*"+j+"="+(i*j)+"\t");, e9 \, f( o. ^( a, H
System.out.println();
4 m# z$ L, g" p8 i, g$ G }9 t/ k0 M' u: d9 U6 b
}
6 u7 b. r# K6 J- q4 q9 {}
! ~0 `1 u* o" Q* ]7 T& d! X" ^. p) z# m! T; s$ X+ x
g7 r0 A/ Y, s5 o: X. ` W6 \6 h1 D% n% BTQC109
$ |3 p# y2 \7 A9 p7 Opublic class TQC109 {+ o, t9 Q( \4 V0 d. M7 s: ^* `- j
public static void main(String args[]) {
% e2 b" p7 e/ c& c7 Q. S( }5 y& B: F int r;/ e L1 V. B" N6 W$ s' i
r=(int)(Math.random()*100+1);
3 s; f$ s3 S1 h5 K; D$ c [ double area = r*r*Math.PI;% I% v8 b5 q( y9 |! r) J0 N' c
double vol = r*r*r*Math.PI*43;
8 A Y3 w! `; n8 |. g' q8 } System.out.println( "隨機產生的半徑為:" + r ); E3 T; E& C" ^" } H
System.out.println( "計算後,直徑為:" + (2*r) );
9 F* g1 K, Q; O% f2 \1 f$ Q7 J System.out.println( "計算後,圓面積為:" + area );
* i* d/ `4 T1 X. m& S* [; ~# N2 ]( r System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);, p! b8 q! E- n. e8 c
System.out.println( "計算後,圓體積為:" + vol );3 {+ w( Z* [ b
System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
0 N# q( e# D0 U u6 n }
9 W \* |: M9 s* b9 s4 b7 U}
$ B. K; S. n2 K8 E2 r3 U" [) a
4 Q/ }- V# ]3 C! R o0 M5 C# X. z. l
TQC110
$ p; ^8 ?' B$ q) nimport java.io.*;
& x; P3 S6 k5 W3 @: Y/ u7 S5 \( J5 \. Aimport java.util.Date;
% p" U( P* M: y5 k" Q5 \* u- Q$ N' m# ]: S# `" W8 S% t
class TQC110{9 X* y0 Q, s: m: I( G( g& H' R
String items[][];: b9 I1 n$ W- M# u
long start, end;
f# N. o" B; ] Date d;
( L) D" E* W3 w4 B0 E: ^% U BufferedReader br;7 D0 G% _) T# _6 Z: o+ Q1 ~& S
* Q8 W3 g8 P6 R" v( L9 ^( t
public static void main(String args[]){) n: j7 ^4 d8 }4 B# z. ?4 v! M
int total = args.length;
6 p d K3 \# I- k$ D int pairs = total / 2;
5 p8 u$ @. r3 {' o# e TQC110 tte;
- o- x8 ~8 P6 O1 \7 A if(total != 0 && pairs != 0)
* M3 K* [ W3 u, |7 t/ b- `/ J9 H {1 G; f2 Z5 M) h9 s8 O. t
//get value from args..
& o2 e4 H9 ~2 j' u- i String[][] tt = new String[pairs][2];- D! ]1 F/ @/ T7 U/ T% W2 j/ w
for(int i=0; i<pairs; i+=2){9 d+ j3 h9 W4 F+ C2 j+ J
tt[i][0] = args[i];% z; V1 m" r. T% o
tt[i][1] = args[i+1];
# W& S6 W) N, Z, B2 R0 M }1 }; s/ j+ s* u! u7 D
tte = new TQC110(tt);2 V- w7 K% K2 b! u7 M' A1 J9 v
}else1 Y2 F2 @+ T& [- n! h. d
tte = new TQC110();9 \9 P2 k, a7 L: B. w9 {
tte.start();' U8 y: [/ c8 l9 c5 D9 `
}- d3 J {- T8 S9 U. A
$ R/ [& f7 A3 E/ A4 m n" c8 s TQC110(){5 M) L2 g& l2 x* ?0 k
items = new String[5][2];
- }( ]! ?0 g1 u6 \$ W# I+ o items[0][0] = "電腦"; m' c; S7 N' _
items[0][1] = "computer";
- h- ~! l& Q, e' d. p0 O items[1][0] = "資料庫";
; i' d! b- o# N2 |! o+ Z6 a items[1][1] = "database";
* P2 F" V4 x# k" S% S3 m" ?6 S* f, ` items[2][0] = "語法";" }. q+ Y6 A& i7 Z, Z; d
items[2][1] = "syntax";3 N+ \6 a* A6 j |8 j9 u) ]3 _/ {
items[3][0] = "學校";
. E* [" r; I. D- F' g; e items[3][1] = "school";; c1 J# Z9 O5 \9 V/ O
items[4][0] = "假期";/ S( _/ ?) o. |1 M
items[4][1] = "vacation";
5 J$ D7 W6 ?9 M* \. h4 v" [5 u //make default value, L$ g3 b4 a4 A2 g( q
br = new BufferedReader(new InputStreamReader(System.in));
3 U; {8 T- G* D3 Y }
9 p% n! r+ B3 n$ N
2 M) k2 E$ P( E5 a' o+ \& k7 I TQC110(String[][] it){
" ?. e" ~) |* D items = it;
6 k. ?" m9 q6 d4 J br = new BufferedReader(new InputStreamReader(System.in));1 `: K% y. _3 e) C
}
5 d# l8 [. R" L4 ? 1 J9 g5 s$ ]8 g' \2 g% [& C
void start(){
) r* y# a( ~0 |4 t String ans = "";
% h( X: \$ `1 o int correct = 0; // 計算答對題數% f7 I4 v) i, e, ~7 c+ g5 m/ r
d = new Date();# f' i6 `4 p! h5 `( [6 L
start = d.getTime(); // 開始答題時間
, }9 v$ v! V9 M# @ System.out.println("請將題目的中文詞彙翻譯成英文單字!");: ?% M6 g; k$ d2 |/ {0 j
System.out.println("輸入英文單字答案後請按Enter鍵:");" ]2 g2 G6 t# L2 K
System.out.println(" ");- N: O1 e7 ?6 J6 T
for(int j = 0; j < items.length ; j++); R6 E* x6 F4 \: @8 [* }, [# @
{
3 C' i( @ G% X( P0 S System.out.println("第" + (j + 1) + "題__ " + items[j][0]);0 I- Y! s( j/ ^0 Z( C8 B
try{
6 B+ R9 g& Y9 ~+ v9 \ ans = br.readLine();
0 _" ?- S* v4 f6 E6 T! \ }
, I- O, m" s: c catch(IOException ioexception){4 ]& j% R, X& d+ ~. x7 E
System.out.println(ioexception);9 ~2 ^. c/ z& `+ Z
}
/ W" k# F; d% p3 \% }; H if(ans.equalsIgnoreCase(items[j][1])){
4 X- D8 a' @% X2 M2 j2 { correct+=1;
/ h+ }* R7 }# X7 J3 D$ Z" [8 U% w System.out.println("答對了!");
. C8 L& T& \! }! n e p H/ a# z0 V //count correct
! f8 [! {9 l4 { //ouput correct message
, ~, U/ _2 h% o) {; I+ j }else{
$ h1 s- t/ b2 `) w( g5 U, c System.out.println("答錯了! 正確答案是:" + items[j][1]);
- k ?% W# j! s& I6 |! ^ //ouput incorrect message
1 r/ C; o; q% [0 q) \ }: c3 @* {7 T. t W" q+ L/ H' z
}
9 z e7 N+ U3 r ^% f' F
" w' p+ x/ }5 M d = new Date();
2 E8 @ d1 @7 l6 y, U2 ?( { end = d.getTime(); // 結束答題時間* S& G( x% a+ F, Y
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");+ C4 E3 j0 S7 C+ t
System.out.println(items.length + "題中答對了" + correct + "題");- Z1 S+ u" ]( ^% B0 g$ M, ?
}
7 ~5 X- \0 C! k" g) K- o } |