TQC107
' ~. b7 H% i# tpublic class test{5 {/ q0 v5 y7 g
2 h; O0 [! L% i+ m4 e9 T2 P7 J
public static void main(String args[]){
u0 l( ]* f: y+ \! Y
0 p8 [4 k, ~$ q4 q$ Y //0 1 2 3 7 W3 e& ~( [" J, q) i4 W
//1 1 2 3. r$ {! `1 a) i3 @- w& N" Y) j
//2 1 2 3; {+ b( n. Z9 B* [5 `+ K
; \7 @- W, _% F# w6 Y$ h float tot = 0 ;
; Q. ^6 Q5 B @& C# m/ O% s8 @ for(int i=1;i<args.length;i++){( U. W3 r5 r: c Y
tot += Float.parseFloat(args[i]);8 t( l* O U1 G6 E" r$ p
}5 T" o: ^' `/ g8 B: C/ c
tot /= (args.length-1) ;
' ^2 _% ?' C: A3 E
: W$ v5 i9 g' J, O! R' E4 L0 O1 g if(args[0].equals("0")){ S4 W1 s" n2 @* T
System.out.printf("平均值:%f",tot);9 y0 q- G a1 u- ~6 [$ A; S
}else if(args[0].equals("1")){
`$ B8 x# A! r6 l! U4 c System.out.printf("平均值:%.1f",tot);7 N! z. O* V! c- g( \/ y
}else{+ B/ \6 X4 H" x8 x
System.out.printf("平均值:%.2f",tot);
* X6 K; ^5 O4 N }- x; h* w, ~. a: X! e
+ a4 |. w3 m& z" J2 k. J3 x' c
/ e* ?: c" V0 ^& n e
}
+ e& b }" |) n
: I6 B0 o3 P" ?3 M1 \# O% X; h9 I, M5 y3 N3 x: M1 I- f; g3 x& Z, m
}
- K6 E1 e' [& p# v" FTQC108
: G" R2 O- [% {8 @: s2 z# {import java.lang.*;
9 i& E, d. v) p! g9 O, V# S2 c( d/ E3 t5 N# R# |4 a4 F
public class TQC108
* ^9 e+ ?. X. N" A. X" Z# L{
+ |# B- u* h8 o' O+ }+ s u/ U public static void main(String[] args)
: R, m5 ^2 i& U9 @+ Y- S {
7 E( N7 Y2 G; Y" B for(int i = 1 ; i< 10 ; i++){" Q- P% g4 B9 u, }, E8 o" W& p
for(int j = 1 ; j <10 ; j++)' z) ]0 z0 e! D4 o. r; Z2 \
System.out.print(""+i+"*"+j+"="+(i*j)+"\t");9 i$ E9 A5 b, X- c4 I
System.out.println();
8 e* e( z! j) u5 D P! P h }
1 j$ S3 Q1 c# k1 k# h7 ~8 t9 s0 b& g }& L% \2 a/ v6 X2 L0 z/ d/ n
}
% I5 z/ b8 y6 J9 R6 [
& b% |( X5 ]% b. g* d6 L
. V e$ C+ F% |+ v" r+ v- fTQC1090 v/ ?2 o) k/ V) i, u0 S
public class TQC109 {, f: p7 }- `+ Y3 A
public static void main(String args[]) {" S* l' n7 k8 m5 h
int r;: g0 V& I( u# k) ]1 a6 g
r=(int)(Math.random()*100+1);) V- D! Q3 O* p2 N2 C
double area = r*r*Math.PI;
8 V* P6 M a( }8 G c double vol = r*r*r*Math.PI*43;
, N/ L. U3 l5 y7 W. J3 ~2 F7 T System.out.println( "隨機產生的半徑為:" + r );( _$ s* H( M, A( a* R7 l- U1 s
System.out.println( "計算後,直徑為:" + (2*r) );. K) B% Z+ h3 T5 Z* M
System.out.println( "計算後,圓面積為:" + area );' F" Z" m( i! `4 u6 i) W3 F) I
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);9 N) B) R! a( a; c6 H
System.out.println( "計算後,圓體積為:" + vol );
/ ?0 L+ S3 c9 a, X System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
2 ?/ F0 i* E0 `$ U' K }6 j4 |7 \- r! U$ c) o7 O
}+ u D2 H: ?. e$ E2 F% L* J4 c
2 R+ L, F4 L0 y& p, e/ E! Z
$ B- w; y1 H6 H {" r: r; e% V
TQC110 1 L) n$ q6 x* l" o7 }% T1 h
import java.io.*;
8 Z# R! O. v% p9 C7 Nimport java.util.Date;8 o2 S) ~0 `8 w# P7 T
0 r5 c% f1 U7 z class TQC110{
6 x$ T4 e. S/ y ~# A r String items[][];
0 X; u9 S( e) F long start, end;
5 {+ a+ a; {# Q: T Date d;5 M' a( M4 M$ M
BufferedReader br;" N0 L5 a$ K1 k! F" Q
4 `0 Z$ ]5 J0 B: ^- O* q: N
public static void main(String args[]){; D/ B- h9 l+ |/ y
int total = args.length;- ~2 V8 B7 j* {5 K7 L& s9 a
int pairs = total / 2;* q3 N+ o& h( `
TQC110 tte;
# b, w" _0 P# l3 p, p" J if(total != 0 && pairs != 0); {% W8 E" ^* `
{
- Z+ Z- E& X0 X6 A: t) B //get value from args.., {7 b6 t$ B& y" _. j
String[][] tt = new String[pairs][2];
- W6 L% [; c+ D; U6 f' A for(int i=0; i<pairs; i+=2){4 Y" x9 m4 }! n- W W7 o( m
tt[i][0] = args[i];; G1 Y) X9 L) c( {2 u
tt[i][1] = args[i+1];
+ @( a, ?, j$ k. S! j' Q& a }
* C) b" S$ A& J5 f5 m9 _ tte = new TQC110(tt);* V0 i" h+ T4 {; x. ^/ b) E. e5 _4 m
}else$ ^9 }: I( t% Z$ l" t
tte = new TQC110();
% q3 |% @& c3 Y6 j tte.start();+ a6 E. u( D, x: K
}, ]) ?" B& l! r7 d7 h
# s7 ~/ K, P @, U# r p1 ^- {8 j
TQC110(){
& A& \ d3 g7 Q8 Q/ C% H- l; ^% w items = new String[5][2];
! a: N; r) E, _3 K) s items[0][0] = "電腦";
1 o8 d& z& ~! f; z items[0][1] = "computer";0 ~9 h @& h$ ~" v% B+ M9 ^& B# M( |) ?
items[1][0] = "資料庫";8 ~, K) w, M5 G3 `0 I$ [( V
items[1][1] = "database";4 h3 ~# [; _* o& R: O% r
items[2][0] = "語法";5 R# r/ k, ?* ?. ], i
items[2][1] = "syntax";0 c- D7 ^6 r4 A* }% Y. l a3 N
items[3][0] = "學校";1 N3 ]; ?, o% k
items[3][1] = "school";
' V2 B/ ]6 v0 l% _( p2 x/ H( N items[4][0] = "假期";
: R0 s. A: ?3 Z& x, m; E1 v/ }1 Y items[4][1] = "vacation";
0 t& E3 `5 f5 S //make default value5 T( {3 `2 N U
br = new BufferedReader(new InputStreamReader(System.in));0 Y& f, j6 Y X) c0 N
}
0 F8 x O0 x% T4 Q7 [ % p& v4 h7 T* C# J% L# M% R
TQC110(String[][] it){9 Z$ q! }) k. ]# n" D R+ o. U
items = it;
' V5 e- H1 g# Z' `1 k2 j/ p br = new BufferedReader(new InputStreamReader(System.in));
8 H2 z5 Q) }# t" y1 B9 d$ D$ i# x* c }
( b( c' S! k& [# X
$ ]/ N' Q1 P7 ]. } void start(){
6 R( {$ ~3 {$ x7 ] String ans = "";! I: V L7 a# a A7 L4 g
int correct = 0; // 計算答對題數7 s. W8 [9 q+ Z4 o) m; @3 n y
d = new Date();
5 r7 R# q! O* L6 ` start = d.getTime(); // 開始答題時間4 X( {: @3 Y6 H% D! l' Y& t# Z
System.out.println("請將題目的中文詞彙翻譯成英文單字!");0 z! ^) c) B9 P% E. r8 b
System.out.println("輸入英文單字答案後請按Enter鍵:");
' P" X3 I! m0 O# T) R System.out.println(" ");5 q: `6 {) f% q" M
for(int j = 0; j < items.length ; j++)/ K& x2 n5 K# h, \
{
; R; \5 }; K# I& `9 O System.out.println("第" + (j + 1) + "題__ " + items[j][0]);1 b% K- q6 [2 d6 _# L/ L
try{9 C- M a1 b; l+ X7 P; v
ans = br.readLine();1 {/ X9 q! b5 g% n+ K/ X
}
' y' P) {! W5 n# t, J* w catch(IOException ioexception){
a' m: f. r! c) v4 J System.out.println(ioexception);- X" o s% z5 r% F
}# i. R) E8 ~. S' j( }
if(ans.equalsIgnoreCase(items[j][1])){
6 c( F E1 {5 T8 D correct+=1;0 d8 ?: G' _. z4 o
System.out.println("答對了!");7 S; r/ a q! Z: S7 g% B9 {
//count correct1 B, [ m- n5 M9 k4 f% j& S6 L, v
//ouput correct message6 a! o3 |' y( [$ T
}else{
' }' u( r$ [1 K- U' ]; b System.out.println("答錯了! 正確答案是:" + items[j][1]);
/ z; `$ \( \ S3 b //ouput incorrect message
$ k; P% e: c3 Q2 ]4 Q }
, W; g7 m5 `* H3 i! H# J% t5 v }2 ], [! B* e& h
' z/ n- ^" i4 ]$ s d = new Date();
' u4 J0 K" Q9 [* d! O end = d.getTime(); // 結束答題時間
! t0 H0 |. _, I' U) [ System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");1 v; M3 c5 u9 R3 s
System.out.println(items.length + "題中答對了" + correct + "題");2 }9 s- s I4 A6 R0 M. ]
}
$ S, t6 o! ]' m( V7 | } |