標題:
TQC107 ~ TQC110 答案
[打印本頁]
作者:
許逸瑋
時間:
2012-4-8 20:06
標題:
TQC107 ~ TQC110 答案
TQC107
+ L6 o: {$ _# b- j9 u$ j
public class test{
9 s! M" {9 W0 ~# c6 b; n0 F- f
) B. x: ]" e0 C0 c. w% {
public static void main(String args[]){
1 |. ]/ u2 m6 A% Y! ~
! d( Q. }3 q r) Z
//0 1 2 3
f. ]4 F. ^/ C, O8 F/ `
//1 1 2 3
9 y- |# c3 M; R/ q2 c* c- p d; n
//2 1 2 3
- T/ o* y! f9 @! K0 S% d
2 f# f6 w/ D% R5 n+ ~; Q) E) ^
float tot = 0 ;
9 X- A5 @5 x% U* N
for(int i=1;i<args.length;i++){
- \& p, g0 b4 b% s6 d
tot += Float.parseFloat(args[i]);
, s1 k1 o$ M5 l& k1 D
}
" ~8 T2 o. Q* ~) ^
tot /= (args.length-1) ;
8 N+ u+ p! q8 w- A" k3 n, G- c0 @& l2 x
3 e1 |! w' X) j' a* N7 k" i+ }
if(args[0].equals("0")){
. z" q! {/ `% e" |9 x/ N3 J
System.out.printf("平均值:%f",tot);
) Z' ^) e! N" f+ |
}else if(args[0].equals("1")){
5 [" h0 L0 M$ a
System.out.printf("平均值:%.1f",tot);
; v1 d" A3 q+ B7 U- w
}else{
; K4 \- o( X" i
System.out.printf("平均值:%.2f",tot);
5 L# o; w$ [% C2 ?
}
" M; A+ M* i% d. P' c
# N# Q- F9 A9 t2 u, O
; m- u! Q9 `" E8 q" w: Z$ Q
}
0 V' g; ^5 I$ P
, ?6 e* O' x: W! o. h( l* p* T9 S- t
& y) I( B# S) L$ D6 H8 ]
}
h# I7 l; R- b6 k
TQC108
5 C2 D0 r. X! L) o% {
import java.lang.*;
" n" G- f; s9 P3 V. a' _2 j# g
# t, U) L, |1 c: X: H- V) ~
public class TQC108
! g$ z' ]0 P$ P( [" b( W: P6 j
{
8 Z$ a2 e$ T1 v' [6 X. f
public static void main(String[] args)
4 ?0 l$ {' z; I, k7 m
{
! w& e, [4 {" m. M; _- M; t1 {1 {
for(int i = 1 ; i< 10 ; i++){
$ k+ M5 E* S1 W* A
for(int j = 1 ; j <10 ; j++)
2 e% X, [0 Z7 S4 l* P& T I
System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
8 k% C5 u3 {2 R
System.out.println();
2 Q( w; @0 ~. {" I8 B7 F. f
}
/ i5 {. `/ R2 q7 I
}
1 Q9 U4 P1 I, T, F- d
}
3 D1 p7 l) K7 V/ J1 L$ K! @4 N
" p- x Q; r8 k( l% V4 k6 J
% [* z5 _6 O: R& M
TQC109
$ |6 S# Q: E$ q" M, ?
public class TQC109 {
2 B2 l7 I5 K1 E# J4 A8 E( I
public static void main(String args[]) {
4 S' V3 l! q! x: y( [
int r;
7 M" t, I1 u* W5 g) Z
r=(int)(Math.random()*100+1);
1 f/ e; z! |* J# R* G+ J3 a" n ]
double area = r*r*Math.PI;
: }8 ^# k. I1 W# |) K( w$ a( b! X
double vol = r*r*r*Math.PI*43;
0 W9 d, B# A$ [5 Q$ R8 t- A7 c4 K
System.out.println( "隨機產生的半徑為:" + r );
# [! V$ f7 g9 F8 {
System.out.println( "計算後,直徑為:" + (2*r) );
% o3 P) v+ e% n& d% S
System.out.println( "計算後,圓面積為:" + area );
0 B I; l" G' t0 l6 b
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
. b2 O- [3 ?& ?0 N' F3 ^# D4 u* N
System.out.println( "計算後,圓體積為:" + vol );
6 c* r a( F) ?
System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
8 q, O, M! h. M! r5 N7 `
}
& @9 z, U. u! L6 O" a
}
% Q! N( ?8 o; l
* t! z5 _( r4 J) e1 Q
+ ~+ f) c( X3 `
TQC110
( i$ `- e1 ^) g
import java.io.*;
* y8 U5 j& a. J5 e
import java.util.Date;
9 m; q; ]7 @- Y" n+ q8 k, o# V
. J5 m% |* Y+ V7 y0 q- _. ~- S/ i
class TQC110{
# B6 g9 G+ p" q
String items[][];
9 q0 v: t; E6 p: S5 Z2 N
long start, end;
4 ^ I6 w3 }( c( R; n
Date d;
& ]8 `* \7 M" E$ h' [7 w* V" i
BufferedReader br;
, a: k4 N4 P0 R& U) Y' Z3 m. \
3 p' o; ]0 J* k8 ~( G' A% x
public static void main(String args[]){
1 @4 T q1 J6 x. [. j/ }
int total = args.length;
; N& ?3 B6 }, b
int pairs = total / 2;
% i' Q" Y) r% l3 e4 E+ X; |
TQC110 tte;
/ v( d& @: V; L( ~+ \
if(total != 0 && pairs != 0)
# |! r8 m9 S: m) ]* {
{
9 {7 [+ b! j; s. e/ T; Y/ B6 _
//get value from args..
]2 |6 R0 j+ r
String[][] tt = new String[pairs][2];
( h: C4 ~* u0 {. h5 ?
for(int i=0; i<pairs; i+=2){
% ~! m; p, g* j
tt[i][0] = args[i];
6 z4 ^; x& I+ W/ `( P
tt[i][1] = args[i+1];
% `8 k+ i v i6 L* g7 K- t
}
/ I% @: y# n" ?3 ~; [
tte = new TQC110(tt);
# w- W8 _- b% m2 x- N
}else
\+ m3 F0 R. c4 K. q. y' C
tte = new TQC110();
1 E% q/ _: v3 ]% E& k
tte.start();
5 A- d1 F$ z+ L8 u, ^& z O; R
}
4 F( B4 M; }& n9 o% G$ h
" L) f+ T' p. b6 {
TQC110(){
7 t* x% ? h/ Y) k; ~; R9 [ B4 ?& s
items = new String[5][2];
( C W& k8 n' l+ L1 a% `! S
items[0][0] = "電腦";
3 `- s6 W D5 ~' y
items[0][1] = "computer";
4 b1 [8 T5 P- f; a' K$ c
items[1][0] = "資料庫";
* I" c4 ]% F& P3 \: X
items[1][1] = "database";
. o; ^2 r. R; x2 s. c( E/ Y
items[2][0] = "語法";
# M+ L3 d$ I. [3 Q, ~( l: Y' y
items[2][1] = "syntax";
" F/ N- I9 A- m8 x; X$ v+ ~& z: f7 P$ U
items[3][0] = "學校";
& L$ D8 L$ h5 |% v! Z$ d8 F
items[3][1] = "school";
9 u2 ^& g/ O" Q5 A& ~7 I7 X& D
items[4][0] = "假期";
5 {1 j: z- [* J2 w6 L$ u9 }
items[4][1] = "vacation";
$ P! E4 t) G* m
//make default value
! N, J% f! R% @8 _
br = new BufferedReader(new InputStreamReader(System.in));
6 q" M- d% l8 `, M" ?
}
& T5 M2 l/ ~+ g7 W9 ^9 e" r9 n
! \/ b0 B! ]( u' E1 x6 J8 E8 Y
TQC110(String[][] it){
# s1 h0 ]2 b" z( H3 a" N* M
items = it;
: m) Z" I6 v$ P0 ^# `% L
br = new BufferedReader(new InputStreamReader(System.in));
- p6 w2 u* i5 U( j# d
}
, V* R: [8 x+ O. v8 [( A8 b( M
2 S" V: [. H7 k- f- V
void start(){
: D; k4 }- s* n3 a! A' M
String ans = "";
5 ~! Y% `' q3 _1 p8 z5 [- q
int correct = 0; // 計算答對題數
; T3 P4 t5 K3 g( @* ?
d = new Date();
2 W6 G" ?/ G3 F* ~" |5 H
start = d.getTime(); // 開始答題時間
* g8 j" w6 T* R2 A# A2 }% H
System.out.println("請將題目的中文詞彙翻譯成英文單字!");
) h. w! L4 C0 E v+ W4 T; ]
System.out.println("輸入英文單字答案後請按Enter鍵:");
4 z1 X' M3 j0 X
System.out.println(" ");
; \8 ]+ E { ?6 \. W
for(int j = 0; j < items.length ; j++)
- F: D7 u3 L% ?; G( l3 H" N
{
! \- ]6 J( ^0 _: J
System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
# v' ?/ }# Z( m9 _1 y, w% {
try{
" g( s8 d. p( c8 S3 Y& d' W5 J
ans = br.readLine();
: y9 Y [/ P2 i" O. r7 I G
}
( G& e! f9 e; ~
catch(IOException ioexception){
9 H; L2 \4 R" p/ w, ?* _& t; c2 q" S
System.out.println(ioexception);
6 ?, Q/ K& ^+ R, e" U9 H
}
# M8 K' z8 t2 y! n% c
if(ans.equalsIgnoreCase(items[j][1])){
) {) l6 z4 V* o
correct+=1;
& w# z0 n! K; _5 w% O5 [ g
System.out.println("答對了!");
& A+ E& b6 A ^7 x- f7 u% c
//count correct
5 q% l$ g9 q# D
//ouput correct message
9 V0 v; G" a8 @9 Q' z: O
}else{
# D9 y+ s% L" k) Y% ]& O4 b
System.out.println("答錯了! 正確答案是:" + items[j][1]);
7 m ] G) U0 U, U3 I; x# D1 S0 x
//ouput incorrect message
/ `, `6 l' U% }/ }3 c! q
}
+ E) h# N/ d6 k! r
}
T% d. C; G- b
( N8 [4 N/ Y% P% C8 c+ K8 Z
d = new Date();
$ \* j9 D, [5 ^
end = d.getTime(); // 結束答題時間
/ G( v* Y! K, i$ O+ @$ n0 k
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");
* z. \: X! a k) c3 B
System.out.println(items.length + "題中答對了" + correct + "題");
% |1 _0 m! c. j
}
M) y! C4 e) m7 Y, ]
}
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2