TQC107
" q7 r; v% D+ u- h7 ypublic class test{
, A& D! o( k' C; M% n7 G2 h
! E( `+ x. W4 }8 b' }' s' r/ o$ o9 {) u public static void main(String args[]){
. ?$ y& o2 h( m5 z3 ~ ; W% J5 M' M. a% T: d
//0 1 2 3
$ D: I) T% K) s0 Q, k' m$ j# L //1 1 2 3# N* g. x1 S) P. \; c( t2 f
//2 1 2 3* l4 S7 a, c5 [: @" m
$ \4 ?, Y0 Z2 b o9 [ i* d/ h5 N float tot = 0 ;
* t( {9 w& ` i8 R. G for(int i=1;i<args.length;i++){
0 f X/ y9 L- C tot += Float.parseFloat(args[i]);
+ L; P: j9 R" `/ K7 ] }
/ }+ y# J: B: w6 A1 r tot /= (args.length-1) ;: [5 J* `9 Z( j% \- X- Y6 A9 s2 G
7 I: K, q9 Q" u" d if(args[0].equals("0")){
1 I+ A& }7 o( z1 y; ^2 j' `$ }: i System.out.printf("平均值:%f",tot);
6 w% E8 s6 |7 R; k, R. W }else if(args[0].equals("1")){- F8 i/ P' Z: |) _ g
System.out.printf("平均值:%.1f",tot);
, @& _+ j; |0 Q# ^/ i }else{6 T/ c2 G# A4 C8 W% \5 ` j; [2 i
System.out.printf("平均值:%.2f",tot);& k% N8 O5 ^4 m' Z# b) _ a& e
}6 ?# X& J; W% F- G( [4 W$ F0 F/ F0 W
# U* E7 M" a M% G6 i: u ^
|0 I4 b( ~% j0 @6 @+ D1 z
}
$ D: B1 u0 g% P% m5 m- z: O
; m0 l! ?- ^- i# z O! r' L; e X+ d
}4 ] g+ c; e, v3 D
TQC108
( G' ]: y- |# o0 z R4 {* Wimport java.lang.*;* k: G7 y& U! R X4 e
; J' o( _) t8 v# s! a) B
public class TQC108
8 W+ |3 D( V2 }9 W6 O{
4 n! l1 ?/ E5 d' Y public static void main(String[] args) + d3 l; ]1 w- J; ?2 L6 d
{5 S% ~6 G2 ?, [& E8 Q& m
for(int i = 1 ; i< 10 ; i++){
% @# w7 x+ q0 H: h# O& r4 I4 E for(int j = 1 ; j <10 ; j++)
" _; q$ q, V3 Y" t$ { System.out.print(""+i+"*"+j+"="+(i*j)+"\t");1 O( N2 y9 d3 b7 j# Y6 I' ]$ c% g
System.out.println();5 S) N# |" |) E0 w$ r$ h) _/ y
}
, j- A* m! I# z, o }
0 e4 n8 N8 L! Z2 V# R2 r}
* v; H: o$ f) l/ M: e( t1 _
* w' [3 r' @/ {' F# a- m
' V, y7 L4 \- w1 \* ~7 b' C5 WTQC109
: @1 a# P0 N7 M6 c% D/ Z& Wpublic class TQC109 {
l2 H/ x! q6 R* t! T3 K public static void main(String args[]) {; c d3 l. g! K) Q" T7 a
int r;2 ]. h3 ^6 o9 G$ Z6 _
r=(int)(Math.random()*100+1);
! e. |. c6 D6 n. l: F9 q: l. u% ^ double area = r*r*Math.PI;+ Z) B# P) u9 M3 W+ F
double vol = r*r*r*Math.PI*43;* x$ s- C3 H: P" T7 M$ Y
System.out.println( "隨機產生的半徑為:" + r );
# n2 X) n+ ]0 ?/ F# x' p System.out.println( "計算後,直徑為:" + (2*r) );6 U. ?% C8 B; N* l, [; C
System.out.println( "計算後,圓面積為:" + area );3 a. R0 y' i) T$ w3 ], W
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
0 b; y; {/ P! T& c System.out.println( "計算後,圓體積為:" + vol );% u2 G3 ~" L% }- v" c ]
System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);! }# {9 a$ d: V4 Q; b
}& {2 U( p$ o" F6 o
}
# J- r2 J: ]8 @1 t) [' T' _; z9 j3 L( X# r5 l: ?; j& z
' w& Y3 Q& d9 v8 @# Y: t+ vTQC110 % i+ J4 n" @' }) k6 S
import java.io.*;
9 |& a( m5 b2 n; s( Nimport java.util.Date;
2 u- M& w. z2 \7 T0 n+ j2 o5 Q3 t; m. ]- R4 ~; F! T+ A- U
class TQC110{
' P8 L( ]" B y. E* e String items[][];
; c5 ?- x0 z" }, O long start, end;
* u7 C0 C [; D- _7 q Date d;$ I. M' B- X) w; o9 p$ g
BufferedReader br;
4 t8 q4 }2 R {) _3 m2 l' n5 J
public static void main(String args[]){% D2 H8 M5 x- H% x
int total = args.length;2 w& y, l! D3 H8 F% ]8 a/ r
int pairs = total / 2;5 G. U" E. P# `+ k
TQC110 tte; a2 }# q; h$ E8 ]) K1 o
if(total != 0 && pairs != 0)
3 T9 _: B& T+ Z( d" b, g: _" V {5 Z v2 u) K: ~0 T; d# p! X, j
//get value from args..
+ D( r0 M" {& N0 V; W+ n String[][] tt = new String[pairs][2];& W1 D* Y6 m$ @# V! J$ D
for(int i=0; i<pairs; i+=2){
/ ^4 m* i" X2 j) j9 R tt[i][0] = args[i];
; @# q' h7 J0 z2 ~% I# R+ |5 W tt[i][1] = args[i+1];
2 ^! q0 ~! C' V7 Y' ~2 k }6 K( p# E1 B, Q6 @! O
tte = new TQC110(tt);
5 ^/ ]5 ^. ~6 q( y2 R }else
4 Q) {, Q2 j* J3 F tte = new TQC110();, h+ w8 U. [8 K
tte.start();
: O4 c) W% e [0 `7 Y! w }
. X7 T6 v2 d- v
1 o$ \% |5 [6 \4 T: A5 |: t% G TQC110(){) z6 U& ?) l% ^7 C8 j1 m! h# o
items = new String[5][2];
( \$ W1 t6 `% T items[0][0] = "電腦"; m9 _1 K" R+ i6 @
items[0][1] = "computer"; Y2 e( Z0 T8 V1 N* n
items[1][0] = "資料庫";
( }' a9 Z9 V) q; F$ b items[1][1] = "database";0 ?7 P0 @9 A: i4 d- l0 c2 {9 H
items[2][0] = "語法";+ b% a( e# J6 y/ x6 r
items[2][1] = "syntax";3 l" i/ J! p+ O) j! ^
items[3][0] = "學校";0 D4 L6 {/ B" c& D
items[3][1] = "school";
4 ?! I' Y# G' [$ z( Q items[4][0] = "假期";* t$ O- n5 _0 y- D1 [2 S) ~% F
items[4][1] = "vacation";0 N' S! o; H8 M `/ b
//make default value% j$ J/ d& \, n. k
br = new BufferedReader(new InputStreamReader(System.in));
$ K# I; r2 E2 Z } @+ Z: s$ e; V: U, w
5 {" W: N, h& [! ?. L
TQC110(String[][] it){5 _3 O7 n$ l, z- ~) t$ V
items = it;
0 q8 r. A4 }; E i2 y5 d | br = new BufferedReader(new InputStreamReader(System.in));
& m9 H: n) w! z; r/ H }
# T* O* F+ v/ P/ M5 J: U& _/ j
: e9 ^' p2 Y. l% W' Q void start(){
) G9 O l: T- v String ans = "";
6 S' l+ E. B7 O' a int correct = 0; // 計算答對題數. @1 U. x3 v1 ~$ Q* y& z
d = new Date();
8 |8 |! n* s4 U/ J0 [2 _5 f# M start = d.getTime(); // 開始答題時間
3 I7 F$ r+ S+ Z; G% x. I" D System.out.println("請將題目的中文詞彙翻譯成英文單字!");3 J+ G. ^) Q. o+ u" n6 f. M
System.out.println("輸入英文單字答案後請按Enter鍵:");
+ F4 l# _) N5 L System.out.println(" ");9 X6 a7 T, B0 {2 w
for(int j = 0; j < items.length ; j++)
# r# [! |( ~' X% u. l7 L; C; f {/ r' I, t7 J4 r1 C
System.out.println("第" + (j + 1) + "題__ " + items[j][0]);/ F" E7 C g' p% l5 _
try{
8 b% n; R1 O' e, O$ J& k ans = br.readLine();( d% w. V: v$ ^, [
}
" G6 W6 N5 A& H( c6 K' A$ H catch(IOException ioexception){5 K: v6 M( J1 P- g4 F
System.out.println(ioexception);
4 h* B* D) Z% C h* L4 L! J& H }8 u/ g: Z& Y0 E$ C, g
if(ans.equalsIgnoreCase(items[j][1])){( t: F( U# \- d8 a* y
correct+=1;0 Q0 j' B" R( q
System.out.println("答對了!");
- F, p( b+ J' H' V. v# n //count correct& E# [6 Q6 T2 j$ }- Z
//ouput correct message* g/ i; r/ N( a3 C: K4 F
}else{
+ l8 e1 B2 r2 k( C System.out.println("答錯了! 正確答案是:" + items[j][1]);
4 G8 n+ I3 L! f2 f5 Q" y4 W //ouput incorrect message
$ v3 p P' X+ e2 [, x% F }
" R# t/ H* }& c$ T) p, R }# a( S$ V5 \7 H2 |' F/ F/ F( G
! R3 J) r& L5 V1 R$ Z0 a
d = new Date();
' G4 d/ b, y% X! v- t. G2 K end = d.getTime(); // 結束答題時間# O! F6 \2 l5 i0 Y$ [) j, q# S. a. f
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");! Y% |$ |& j+ A5 `6 ^# ?
System.out.println(items.length + "題中答對了" + correct + "題");
5 \/ q( m% r6 K, O" w- ~" @ }+ ?3 s0 ?4 t) b/ X) M
} |