TQC1079 Y; M5 b+ P4 }! c. q3 b- x9 s
public class test{
1 m! y0 U$ u2 M3 N/ A8 j' Z+ k
8 F; A6 l8 p% h G2 V public static void main(String args[]){
. G4 l2 Z: y2 u) @: `8 U1 f
7 \, t, C d- `# q //0 1 2 3 # K0 a5 P1 W) M. Z$ k+ ]
//1 1 2 3& M4 ] f. p- P, e# j p) _/ b
//2 1 2 3) \) d8 q T3 p$ T F4 w
2 V$ [! X2 ~$ a3 R9 W
float tot = 0 ;
* }6 _8 W$ j5 \; T/ a for(int i=1;i<args.length;i++){
2 H- Y' J# m9 l; ] tot += Float.parseFloat(args[i]);) h. r$ @3 X5 a! I |
}
* ~3 v) Z P$ |1 z3 L! z tot /= (args.length-1) ; F) q9 M1 s7 t5 O- N; e
, j' X$ Y6 \2 ?( I$ E# w1 ~
if(args[0].equals("0")){/ |" e7 {- _3 {3 i! i* y' |
System.out.printf("平均值:%f",tot);
6 t; S& m! r* [! k% _ }else if(args[0].equals("1")){
9 v8 K( d/ c; @" O# A System.out.printf("平均值:%.1f",tot);% p# K7 x: K/ M& U
}else{
0 w$ T. w/ \9 g+ N2 b System.out.printf("平均值:%.2f",tot);( ?" \: }7 m* E# q$ W/ `5 X) u4 ^, V
}; |2 b1 k8 ~! \
% o4 R. V, b/ C1 B! n) G
+ g8 z8 h s8 b0 z }! z2 d& ~: ^& r. r# z# f% A; m! V0 o# A
- `9 S: h" k3 x+ I# u3 V" l# ?. q8 u
}
; [" p% w; I) K, F; O$ UTQC108
3 ~' j# O6 _4 gimport java.lang.*;
; _' h! v1 g3 o" a1 Z+ s5 Z) S$ C F5 i2 W2 j2 J
public class TQC108
q& F$ T& A8 M5 |{, e4 q+ M8 O6 d/ X
public static void main(String[] args)
d0 A5 r: c5 H4 Z! U; W {4 [& T# Z' Q: R" A
for(int i = 1 ; i< 10 ; i++){0 t3 v. B$ b% u
for(int j = 1 ; j <10 ; j++)
# H2 l* n# C H d System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
6 M/ P. @1 f4 V3 x y0 x- R System.out.println();! s$ X& e# K0 g/ s5 N
}
7 Q; k9 u1 U, h* y2 | }$ V1 V: A* S: J
}* [4 } ]- Q7 f) e; ?& K
0 X, u0 M+ [. _+ v4 B; n) e# O+ {: S" r' M0 {9 {
TQC109
; F) E% t) q4 D& E$ E$ \9 H8 V. Fpublic class TQC109 {
* S/ A% f8 Y1 u% _. T public static void main(String args[]) {
; v1 p. t# d4 ]! _ ^: h4 A int r;
& N7 e9 B6 y4 _1 m3 o r=(int)(Math.random()*100+1);
1 }3 G Y) f& ?' S1 j double area = r*r*Math.PI;
# V: o; z1 {" V) m: E- l3 C double vol = r*r*r*Math.PI*43;7 ]& P1 r' v# x# _3 l+ I& h
System.out.println( "隨機產生的半徑為:" + r );" N. e' T+ j/ @& W( e& P3 f
System.out.println( "計算後,直徑為:" + (2*r) );1 \$ b8 _' Q8 U; d' g8 d- |
System.out.println( "計算後,圓面積為:" + area );% ~3 q* \5 X5 t; |# e+ i, ~
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);( [3 B4 C, |% m+ o5 @8 Q- g
System.out.println( "計算後,圓體積為:" + vol );! V& b4 f* R6 M/ \$ J
System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);4 \0 T! d9 [ @% Z$ i
}
* f5 t7 w; s8 ]+ Z}
% m- y/ b6 ?$ ]. w" ]+ ?* d3 j4 v+ ?* o- y5 E5 {- l1 H' _
. s" l& f: C% x9 N. gTQC110
: A! k' H; G8 | i3 ]$ k" }import java.io.*;
" U+ \1 B! P- y3 |import java.util.Date;% ]9 ]8 T& E' x
v$ E, B) D( ^+ s
class TQC110{: a; I: Q9 d+ X4 J5 {
String items[][];
4 e! o/ S5 h1 b+ z: J7 U; r/ E# k long start, end;
" |5 z% m7 y9 q( u L; a Date d;
, M# p+ n, q: F4 T BufferedReader br;$ f8 J0 _! Y% q. W: R! a
; y6 q. z: j6 W
public static void main(String args[]){! t" i- H1 |( F- K" j# \3 e8 n
int total = args.length;
+ o2 v. R7 z2 s' Z4 ?* z5 B. J2 Q int pairs = total / 2;1 f, o& @) Z/ I# ^
TQC110 tte;1 J( C5 m0 N1 |' Y
if(total != 0 && pairs != 0)
8 B- j0 C4 f; s3 k2 A$ S/ U {, J. }: I$ h6 k1 t7 w
//get value from args..
6 f8 y) k& c! X String[][] tt = new String[pairs][2];3 _* F- k- u7 Q3 a4 j5 O
for(int i=0; i<pairs; i+=2){
8 F6 J& k& T4 X2 q( Z4 y4 p* {# P tt[i][0] = args[i];
4 m# y1 u% q3 `& Q$ ^9 f7 M Z tt[i][1] = args[i+1];
' P. O! |* Z% |1 w& e }
- Y y8 y' ^+ W5 f3 [( _ tte = new TQC110(tt);
6 [4 `4 _" I8 E8 ~3 e" a }else
' G2 p: w' b5 _; u- n. D tte = new TQC110();
N5 S# _& d [3 _* N0 n tte.start();
1 h* t7 H6 e6 b ]8 i }. c' T& X6 v D% V b
- f8 s" e7 \) H" l" {
TQC110(){4 ` P. I* P1 I7 M [
items = new String[5][2];
+ j6 X- i" }: Y3 x. K items[0][0] = "電腦";& y7 C% a, ]: S- F) R* A
items[0][1] = "computer";
# b/ ?6 W' h3 C& j6 [ items[1][0] = "資料庫";" G) j/ s# E8 Z* R6 O+ D
items[1][1] = "database";
2 U/ Z( v; B3 p3 @! N! o* t8 A, C items[2][0] = "語法";' z/ t. [5 r: `/ i- U& I1 @- A
items[2][1] = "syntax";5 [6 I! m9 L I1 H+ n1 u8 X. G4 o
items[3][0] = "學校";; M: c: A4 ^1 Y
items[3][1] = "school";. v; M. r, X" Q; S; `2 y4 L
items[4][0] = "假期";
% v% e! u/ h& h; l( \ r; ?/ p9 z items[4][1] = "vacation";
" `! s G7 Q( R //make default value+ H0 p% F* ~2 Z' |
br = new BufferedReader(new InputStreamReader(System.in));
1 C# Z+ t0 v5 A' X. X& |" p0 E } V, P( L/ m9 r) Q! ~
* X( v" Q% b G
TQC110(String[][] it){
+ W: A/ K( x3 H) W7 u7 D5 ~ items = it;
( t" r7 c$ H. C br = new BufferedReader(new InputStreamReader(System.in));- V: Z9 E% i% M9 W' h6 L
}
6 y( C2 S# m$ O: s4 ~9 \, a2 W
# p- ~0 L1 f& h& C$ U void start(){
3 b, h2 D4 D7 P" b, {" z String ans = "";
/ e( R! L" E8 `- @# s6 A int correct = 0; // 計算答對題數
9 h( p6 ?( M) n" w5 a, S+ e+ A- V d = new Date();
) x( L' x3 _( v$ m start = d.getTime(); // 開始答題時間
2 u- O+ U! _) L4 x" K5 X3 v System.out.println("請將題目的中文詞彙翻譯成英文單字!");
5 O" z) B0 `+ M; C* {. c: u System.out.println("輸入英文單字答案後請按Enter鍵:");
& P9 l2 c Z+ s7 z System.out.println(" ");( I9 \; E, @# Y" O' g
for(int j = 0; j < items.length ; j++)
+ r+ e: |2 y) T" w {
2 ^0 @( h5 E) n# w: v- ~* C7 T/ K System.out.println("第" + (j + 1) + "題__ " + items[j][0]);7 }% d* X" e+ q- q( K
try{
: E# F0 q! ?4 m ans = br.readLine();
$ X% `+ y1 y: d" G7 | }4 E& R/ v, S5 n; L( L9 l3 t* m
catch(IOException ioexception){
+ j* P+ K+ ]4 ~7 U System.out.println(ioexception);
2 k2 e# u% d9 P7 p- X, C: d4 i B }
9 N0 z0 v/ ^" S( S% i9 e if(ans.equalsIgnoreCase(items[j][1])){4 r' J7 c1 V3 W1 W7 r* a2 m
correct+=1;4 m |' i0 b1 A8 p2 P
System.out.println("答對了!");
; s0 q2 P: k& h; l& h P //count correct
7 Z9 l4 h/ k0 {- I/ w- J. H //ouput correct message
7 G o1 O" t/ j! m" w }else{
) G. _$ W! l |8 x System.out.println("答錯了! 正確答案是:" + items[j][1]);
* O! l2 N0 M$ m3 S //ouput incorrect message
7 ~+ A* W8 ^+ @) F }
# f- `8 `: v% x' Q) g$ D2 U0 w* A }
! |+ H! n# ~: b9 |0 _5 U/ Q, P k8 K9 C4 w
d = new Date();
: G/ P6 x6 ] D8 n. n end = d.getTime(); // 結束答題時間( [3 ~! ]0 T* W( g6 [' Z
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");; V$ d4 Y+ ~& d+ a7 r
System.out.println(items.length + "題中答對了" + correct + "題");
" q/ ~* l) B5 d- f8 I2 B }
9 c* t* O m6 J2 T* I; T } |