TQC107! E% R0 c1 ~' }0 I$ Z1 ? \* l; h
public class test{1 M; ?# f$ l% _# U9 D! P$ j7 H: i) n3 r9 ~
$ N( G* i3 T+ J3 H6 |1 V$ h+ | public static void main(String args[]){
+ U& P5 {, M6 d; b
# E+ x( T7 r7 C9 [ N //0 1 2 3
1 M0 Q$ \. X6 c1 _ //1 1 2 3
W2 p* c* X7 l' A5 t //2 1 2 3. W& `4 v2 ~2 Z
8 R. Q! d/ x/ I0 f
float tot = 0 ;
, w0 m' t1 H9 F5 e; ~- b for(int i=1;i<args.length;i++){1 r- X' M# y) w1 S8 h* F3 q/ h" n
tot += Float.parseFloat(args[i]);
' c1 K) y+ o! Q; b }
0 ~4 w9 o2 ?9 E0 f" T tot /= (args.length-1) ; c" y9 g, s* e F! L) o
$ x5 I1 R$ k' [. o$ q, ] if(args[0].equals("0")){
2 O- @& H9 Q2 @& c2 H* e) {8 ^1 Z System.out.printf("平均值:%f",tot);$ J; A- B; Q# w# u8 H8 @
}else if(args[0].equals("1")){
+ F' ?/ u# d! Q) y; C System.out.printf("平均值:%.1f",tot);$ i0 r! I5 n+ q% d: h. r$ N
}else{. N. |) C# _. R
System.out.printf("平均值:%.2f",tot);6 d' A- L* h' E P; ?8 m. L" P6 B
}
' S2 F% e# q6 z# G+ B1 k* ?
/ d& @! _0 ^4 g
7 }+ W7 l3 [4 J% y7 ? }( O* A; w# k% G1 g" M S
5 k' p2 M' @: Y8 B2 `5 F5 {6 \5 \- F; ] K" c8 p) [
} Q, G! k0 r% e9 _; C& u
TQC1080 O) H# I9 o" C' Q8 x0 {
import java.lang.*;' _( y& G/ N( k
( \4 u9 N5 `0 F6 @9 w- q
public class TQC108$ i: P/ |2 L& D, E
{' @& t3 x: z6 Y. Q( Q% M& `6 P6 O5 i2 Q3 c
public static void main(String[] args)
7 _( ~6 w. ?4 H+ q4 H& u. I* I {- q8 F" X5 l# V" N% m
for(int i = 1 ; i< 10 ; i++){
# a. C7 ` Q1 d* b# N for(int j = 1 ; j <10 ; j++)7 x; ~$ F" w* `* F- ]
System.out.print(""+i+"*"+j+"="+(i*j)+"\t");- m7 W) g9 _- m1 o9 r' X
System.out.println();
5 V- A' W- L& N) ^* U1 V }
1 T7 X- q$ y4 c& i- J' { { }
& g/ W) i- v2 x) `1 |) Q}
! q, p: H( C4 q3 @5 h& @2 L7 M" X2 P& A( s* b& h
3 v U& Q, x+ ^+ [3 o
TQC1096 N& U1 S9 e- i; n
public class TQC109 {6 ]3 g3 Q3 N& H" q \+ `; A5 c
public static void main(String args[]) {! M5 L" u0 N; [8 |, W/ V& H2 f/ g' D; @
int r;+ T0 h! W7 K% V, ?
r=(int)(Math.random()*100+1);
1 n7 z$ x5 @* t- t1 m+ | double area = r*r*Math.PI;$ r- W- K7 H6 J7 ?5 U8 K* X1 l7 _
double vol = r*r*r*Math.PI*43;
+ y+ g; t1 @7 q$ u3 X% L6 C7 N System.out.println( "隨機產生的半徑為:" + r );( [$ a: g/ v2 s% Y3 c
System.out.println( "計算後,直徑為:" + (2*r) );
, B$ g9 }6 o+ D System.out.println( "計算後,圓面積為:" + area );6 W9 ~9 l4 @9 D8 t7 v
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);! u7 |" l `1 |' i+ s
System.out.println( "計算後,圓體積為:" + vol );
9 h/ }% Q; s& S* b6 ` System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
' c+ E, E* I. x/ C }
) U" F% j/ k: [6 s6 G, {}, Y1 O0 `) n# N9 X. U: f1 B' Q
; Q; S1 N: d2 D/ D
% D3 v9 K' r. g4 l/ o7 Z. Y
TQC110 5 N( t: O- J; O2 x
import java.io.*;! p* H1 X G1 m+ T
import java.util.Date;$ y' T1 `9 x, ?9 z- H
' _9 |3 s& c% J. Q0 t
class TQC110{- @3 s; s4 r- C' B" i9 x6 E
String items[][];8 n* d$ X) s- X3 z( i1 v/ T& ^
long start, end;& G' r, A" W! `: K8 `+ E4 r
Date d;, W$ C! E# z) M% B
BufferedReader br;
: n- Z2 V5 {: c' ^/ [' q
3 K: l4 r& ?& |% g( S public static void main(String args[]){' E" z" H0 y2 Y2 a4 E7 g% o
int total = args.length;
! y( h: \6 k. d' S; ^; y int pairs = total / 2;
' W( g* a' D* f7 S" L6 _! C' H9 { TQC110 tte;8 E2 {0 z5 M' ~7 [% M$ g( C
if(total != 0 && pairs != 0)
5 p; i6 X2 U0 N4 @- n3 U$ C {
1 ?8 C: |% l! q3 y //get value from args..
$ H; V% V: q, o: \3 A1 Y String[][] tt = new String[pairs][2];) q- t, {$ b. A |
for(int i=0; i<pairs; i+=2){3 ~1 f( k' X7 h0 O% o
tt[i][0] = args[i];( l7 u& |- @* O/ T
tt[i][1] = args[i+1];
( u' ?. e7 b, g& ?, { }. a1 X1 ~9 U3 Q. t% x% T
tte = new TQC110(tt);) g9 F7 n& B1 G3 \5 F- S+ [
}else: {/ E* D; E+ M
tte = new TQC110();. f* ?$ U: l/ u+ M/ A' ]& n) ]
tte.start();
I J: z5 D" E3 q( K }
- }6 w8 x5 ?' A- q) O+ W0 A0 }
0 F$ O7 ^' r" u E TQC110(){/ r( G+ h, L7 Y+ C g, j3 j, |
items = new String[5][2];
$ a7 m# u3 e2 c; G( I5 E e items[0][0] = "電腦";0 y6 y& u3 C" f) |/ D
items[0][1] = "computer";
2 \2 `; F/ H; {3 f! ?" d: c items[1][0] = "資料庫";1 Y# K. O" }0 T# i+ t9 G9 X- I; ?
items[1][1] = "database";
& V7 G+ p; b' A& w, ~; v/ b items[2][0] = "語法";9 W- }7 l0 x1 r" v, m8 E
items[2][1] = "syntax";8 s+ ^4 v" q( b7 N! X
items[3][0] = "學校"; X' e- D+ P3 O
items[3][1] = "school";
* ]" \$ X* w& W3 t items[4][0] = "假期";) T( i- k8 |% t) H, S0 ^
items[4][1] = "vacation";
6 @+ u+ G5 F) {5 }+ C( z //make default value, M1 s w# i% ~2 ?3 O( O
br = new BufferedReader(new InputStreamReader(System.in));* n n0 v+ l% [: a" g/ ]
}
3 f8 e( s- k% U3 F0 v F0 W ' w$ B- x9 @9 Q. U0 @
TQC110(String[][] it){
3 v6 Y2 U+ ?6 a( D" B. G" Q. q items = it;
, Z5 d3 h M7 ?( Y* Z E0 f br = new BufferedReader(new InputStreamReader(System.in));
1 n# B! _8 S0 n! u- E, q: | }
o4 |3 x6 m. k0 O1 O0 R& J: I7 \7 n 9 _( k" c: _% E3 `9 \- k: H
void start(){: N |' a" Q5 o0 `( c9 T
String ans = "";
. q9 s" O7 x) u* o int correct = 0; // 計算答對題數6 ]% R0 _, R/ ]. `- o2 J# | f6 h
d = new Date();# j. C7 U& P+ l
start = d.getTime(); // 開始答題時間, l3 l+ q# r$ S' F( o& S. W) q
System.out.println("請將題目的中文詞彙翻譯成英文單字!");
& P% t) p0 j3 u6 r* n7 w System.out.println("輸入英文單字答案後請按Enter鍵:");2 Z2 `2 R% o, g5 h% r
System.out.println(" ");
- d& j+ n/ J! |! H2 l, l/ N for(int j = 0; j < items.length ; j++)
# Q1 A3 ~- d7 _) N& S% \ {
0 _" I8 {& Q/ X- G System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
2 n" p* p* H% _; ? try{
) D% l5 w8 K3 \- _/ O ans = br.readLine();
7 H" y1 Z3 |. a' e9 k4 d2 e }
6 N- k. q5 u5 L- y4 a2 d/ p catch(IOException ioexception){
! |0 d2 b7 ^7 G. z0 d$ F. w System.out.println(ioexception);( S: L' e; ^ d8 S. F+ @9 U
}
2 M6 u2 N/ J E' w if(ans.equalsIgnoreCase(items[j][1])){. [0 @& w3 E4 K }$ _
correct+=1;
3 X2 N9 i+ Z) c' l System.out.println("答對了!");7 G1 L5 N5 I8 t$ `: z; c
//count correct
E0 M* n! S- D- i' ^ //ouput correct message$ A/ z7 A# D9 p' ?$ k2 i4 n5 x
}else{' H1 D( V" ^( |/ f) w+ R. j. S
System.out.println("答錯了! 正確答案是:" + items[j][1]);5 I8 W$ n4 r1 v$ W E. }1 ^0 D
//ouput incorrect message9 p! s- s9 k" B' I% W, N
}
. ]% d6 _ n5 W6 E+ m: f3 w/ R4 X }
2 A7 H. F8 }! B1 U8 M1 L5 P3 M
& O. B9 M: ]# u: ?5 X' Y, Y d = new Date();
! e! O z+ _! j- R, h! l end = d.getTime(); // 結束答題時間
7 y9 W. F) R' }! p( B System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");
% R$ [; m$ x! Z1 G System.out.println(items.length + "題中答對了" + correct + "題");
2 @ i9 J; X' i6 Q! V0 o$ x, y) f }
O/ b# D# m. m5 f } |