TQC107$ q$ k0 L0 L5 T }9 b
public class test{
; E4 g! ]8 R0 d4 _- ?; @
9 `7 l/ a2 b4 | public static void main(String args[]){) ?- T, g4 _# x! R
% a* \$ y0 Y S& Z5 x. s
//0 1 2 3 - Z% l; I, c# x! S& ~
//1 1 2 3- o/ a, {& t7 i7 {5 [/ j: u* g8 P
//2 1 2 3
( L1 F) M) U2 O# P
, M) h: ]6 w$ F float tot = 0 ;9 Y. p1 L+ h- W5 p
for(int i=1;i<args.length;i++){
! s7 ?, A3 U; \" b" M5 h2 D tot += Float.parseFloat(args[i]);4 \2 r0 k3 n, W; k; \% M
} g& e% Q P0 q( e
tot /= (args.length-1) ;% n. r) P2 F" ?5 k+ W! j; y7 j7 B# \
' z2 I% ?' Y# X% h4 L) d9 x6 X if(args[0].equals("0")){+ |; Q8 h( ?& \% w# I
System.out.printf("平均值:%f",tot);
6 m/ r( @5 e w) I8 b8 N7 z6 Z }else if(args[0].equals("1")){
7 n( g6 @' ?' o: M: L: X+ z6 k System.out.printf("平均值:%.1f",tot);
& u0 H2 Y4 o, @: h2 Y, F0 T6 i$ \ }else{5 d- k2 i' V, s4 q
System.out.printf("平均值:%.2f",tot);
/ K9 `" W8 p S9 V }. E& C2 J0 K! X" j) ?& x' e
* [% `$ o# I" r& z" u, W * D" l* ] m. O7 t
}4 [0 T. _, T. C/ ~+ n
$ W8 e4 B0 U2 ?* v5 [
) R" `( n' o% w" ]5 s% Q/ G}
7 _3 v4 H2 Q; D" k5 g4 FTQC108- M6 H$ x) P, ~5 O0 O
import java.lang.*;
% m) M# s) {: K: ~# q
2 D' L+ C2 `6 dpublic class TQC108, e5 M+ ~- m# _. f+ E# ]% a. r
{
/ N9 T( \3 ^" H0 U4 b2 G8 r- ? public static void main(String[] args) 8 e: ~/ M8 d1 Z; T0 i2 b
{* }( _1 A. o2 j
for(int i = 1 ; i< 10 ; i++){
z3 n F1 e' O' f for(int j = 1 ; j <10 ; j++)# z) C8 |3 j# m+ o$ v/ M5 ^
System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
/ @# ?& s' J4 q% [; h$ a3 T System.out.println();9 `5 u6 t0 g; R0 M0 G* Z
}
# Q# K, }; k3 w }; L* ], q. D- f/ w0 `0 i
}2 \5 H3 }$ Z( z: M( e) s) H, A
, Z9 Q; t0 m2 r7 x
5 g# G3 E6 M% t; B- q) y# dTQC109: ^: \5 }8 z ~* n
public class TQC109 {
: ?, T) Z) Y( I public static void main(String args[]) {; y" l4 }' `6 E" [3 S) g6 m8 e
int r;
5 f! K5 }& l: w; B r=(int)(Math.random()*100+1);
- c4 l8 i, i, ` double area = r*r*Math.PI;- l) ^7 C. g. L5 b, T" {
double vol = r*r*r*Math.PI*43;0 U5 h0 {$ j. ?9 {2 |: s
System.out.println( "隨機產生的半徑為:" + r );
# y( C+ h+ @0 r, s9 h System.out.println( "計算後,直徑為:" + (2*r) );: x+ e' i6 o2 O) W/ m
System.out.println( "計算後,圓面積為:" + area );) ^' ~) z) \) N; ]
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
% T) }/ b# f6 p System.out.println( "計算後,圓體積為:" + vol );* I6 M o6 M, u$ ^# V
System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
( x6 l2 ]$ y) G2 E8 S; ~ }8 c. P/ L( U6 g) }" j% U) S! Y
}; e* j G5 ~4 P% d& L
# d) S4 _. ~' A, Z: o& v. h+ F% H # X$ X3 A8 W; ^- h
TQC110
V9 U0 U- I2 \8 W- g; e0 F pimport java.io.*;( m$ k p2 M1 S4 |& G
import java.util.Date;" w2 ]0 [' I, m# _: `, F
, H, g r; Q3 N! ?- A8 F' _ class TQC110{! Z' N+ y# X8 d
String items[][];3 {; Y6 t1 j7 B7 F$ L
long start, end;
$ E# T0 b7 l; x( ] Date d;
9 ? }# A- W0 V% m" h BufferedReader br;
8 p1 d' I2 K6 X6 D( E/ Y$ B5 u: x( P
public static void main(String args[]){3 [$ Q" `1 P* Q0 @5 `. P
int total = args.length;
1 I; Y* D4 ~' `4 f' H) B int pairs = total / 2;, w+ o# ^# e* L a; l8 S8 N
TQC110 tte;8 m8 I9 q! G1 c7 E9 K _
if(total != 0 && pairs != 0)
& O1 T0 \* Z$ X6 W8 {% r& R {. I) ?) p8 H5 m5 _9 o+ w
//get value from args..
8 v/ \5 e2 c! K3 n6 Q* ^" u String[][] tt = new String[pairs][2];
3 Z% i( D6 [2 I& L2 L g/ S for(int i=0; i<pairs; i+=2){' r& R% k/ A% H: z: n9 h
tt[i][0] = args[i];
: j7 i9 J# g/ U' V+ O- G6 G' V N1 @ tt[i][1] = args[i+1];! N, E9 T5 v' C) V3 c( _; k
}8 v5 X6 S% Q# |: x. U3 ^# H
tte = new TQC110(tt);
4 k: |' p" S# O4 S) s4 [7 b$ h1 s }else
; i* B9 J1 h: c0 ?) b% n2 | tte = new TQC110();, T% n' Z2 i$ P" }" k6 c
tte.start();" l8 L/ M2 F; f
}" e! n4 g/ n3 _0 q3 I
: P/ O# [* E" A9 {7 ^
TQC110(){3 K8 X. r* ~6 x
items = new String[5][2];5 S/ C2 F% f& T# \$ S' q0 n6 p
items[0][0] = "電腦";9 @2 z! T# O4 N# G$ z6 X
items[0][1] = "computer";
0 P/ t- y' F5 ] items[1][0] = "資料庫";( N2 l* w1 T8 f0 D* m& r( P) }* s2 R
items[1][1] = "database";
& M# H' Y( K! Q L: B3 m items[2][0] = "語法";5 _ |2 }' ?3 A" K _0 a
items[2][1] = "syntax";
: Q. l- L# ^, `$ [$ I r items[3][0] = "學校";# ]9 Z2 S" ^8 l
items[3][1] = "school";
7 h8 d- S2 q. S: }. z items[4][0] = "假期";# G% p: X9 X; M; z) n3 [7 n
items[4][1] = "vacation";
1 E; D; D* h; b' O //make default value
( S5 l+ [7 @ {- \3 T8 T: x br = new BufferedReader(new InputStreamReader(System.in));; A0 O( o' s1 V( K
}7 U7 t6 t b' a, S$ X2 V0 j
, [, F9 Z( y" W) m2 ?# \" [
TQC110(String[][] it){$ H2 y" b5 h1 Y1 D, T" o+ b) d/ s( b
items = it;
2 j. T% I8 C; @4 E br = new BufferedReader(new InputStreamReader(System.in));
- [: @( r1 ?- n; Y+ ?) q- V g }
- M3 f9 p( w2 e# l+ W- S9 ` # I: E" c: M/ _9 Y8 h6 H
void start(){( y7 E y% f% y8 I
String ans = "";
' T* M# X* y. v int correct = 0; // 計算答對題數- F, A, e) Y. u! O, z) v' [# F
d = new Date();- P! u% N3 X$ @- d
start = d.getTime(); // 開始答題時間
2 W, ^9 m" L) i" z System.out.println("請將題目的中文詞彙翻譯成英文單字!");
: B% ^$ ]! E7 O5 q$ l8 O) s; X System.out.println("輸入英文單字答案後請按Enter鍵:");
; Q/ w3 B+ N4 z) w1 C System.out.println(" ");2 [8 r! y- `' c
for(int j = 0; j < items.length ; j++)
2 {, N6 _2 c0 [4 j {' u( p! S7 p3 x' o6 q" b
System.out.println("第" + (j + 1) + "題__ " + items[j][0]);: J8 a+ {7 e Q6 f! g4 P9 d
try{0 s0 E8 ]# N! E$ d. ~# a
ans = br.readLine();
/ ?& Y0 \( J, C9 Z2 G, W9 Y$ { }" {" v1 T+ L) E
catch(IOException ioexception){
+ z' j" B8 s# p* l System.out.println(ioexception);
1 Z: R) |7 C/ ^9 i( \. y }
. ^6 `# G5 A8 }& E if(ans.equalsIgnoreCase(items[j][1])){- G a* V+ ?: ?
correct+=1;
^. H" c3 a; Y" P S/ Z4 _ System.out.println("答對了!");7 f m( b+ x N
//count correct
, g2 F# w6 C7 B/ S# N* e4 [$ T //ouput correct message* b0 V1 s; o; w
}else{' l1 {, J! i# q6 K/ S4 |3 p
System.out.println("答錯了! 正確答案是:" + items[j][1]);
8 C. _2 @4 \/ O) @. j8 ]- @5 j4 |( {% m* A# \ //ouput incorrect message/ d) X! X3 B5 h$ {/ M% K* M$ n
}
$ q5 ~* t4 s( d, ] }4 Z; E" C- M# p1 f% |5 e( @% l
8 U6 X9 y0 ]1 k. k: T" Y/ H9 c) m d = new Date();% L7 i. C* B" x/ z$ E' u9 x
end = d.getTime(); // 結束答題時間3 Z. l7 p6 O+ q- Q# r; ]/ `
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");
8 O. U6 t2 D3 R0 P. A* ]+ Y System.out.println(items.length + "題中答對了" + correct + "題");4 Z6 [/ ]; P% W* N* `- j
}
! t% ?" R% j" ?. e } |