標題:
TQC107 ~ TQC110 答案
[打印本頁]
作者:
許逸瑋
時間:
2012-4-8 20:06
標題:
TQC107 ~ TQC110 答案
TQC107
5 U* C9 A) i. {9 u( a
public class test{
; N$ W) ~8 d7 Y' I+ k* w
0 n, Y- L# H$ X C7 E/ J( N. f
public static void main(String args[]){
1 \. |# N0 N/ X4 v' \( X
: _8 @$ M: r( [2 X2 L
//0 1 2 3
& e% y: @5 @+ y. l- V
//1 1 2 3
M0 L# Z5 d2 ^7 [4 @
//2 1 2 3
/ g2 F' o. p. {8 Q- i
# c- Q5 A4 K6 o" V6 n3 Q U
float tot = 0 ;
+ t* j2 A6 W: l" G2 l$ z7 @, k# q
for(int i=1;i<args.length;i++){
* l2 r5 }& w( r( l" S3 c5 O
tot += Float.parseFloat(args[i]);
$ o" g" r0 b ]) B; R
}
: u8 ^ W( ?% {
tot /= (args.length-1) ;
4 D% z5 f5 @$ x8 A5 H
! I4 W2 X# z2 x$ T7 X" W
if(args[0].equals("0")){
8 B7 i6 f4 W$ D' J& `9 s/ V* l) }
System.out.printf("平均值:%f",tot);
5 c9 Y' O% Y& F7 A' \; T, I1 I# ~. j
}else if(args[0].equals("1")){
* I0 c/ j! i6 n
System.out.printf("平均值:%.1f",tot);
4 V& V$ Y% L; y6 W" V) S" x; b- ?
}else{
) C6 V4 X) c. E* {
System.out.printf("平均值:%.2f",tot);
k2 I6 I7 Q$ k: i
}
' t* d. X; ?7 v
; X( A- _' h+ N/ z/ y
5 [3 K6 m1 J2 r. `2 m4 q0 g, e! N, f
}
# v' R4 P/ J) Q
+ d. Q: a- Z* \0 h5 B
+ l1 v- \( c! T6 ?/ r. ]
}
; Y3 @& W+ m5 p8 v" r! p% i
TQC108
; p( T! R- M( ^0 y
import java.lang.*;
8 i/ i4 Y# L+ J) M, f+ b
. p! g+ x* b! j% Z8 {# f E& K
public class TQC108
! ~# i# \& T. D# @" b% ?
{
5 O h- ?7 m4 v( n4 K$ ?3 M# l
public static void main(String[] args)
' f- @- I& S* M- P+ `( |
{
+ k# J8 i- b! R% _& O, o1 j
for(int i = 1 ; i< 10 ; i++){
' C3 J, f! J( A# h; x3 O* J
for(int j = 1 ; j <10 ; j++)
2 ?5 }( G' I! u- O5 a: q( |
System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
6 L9 r3 Y. v# U5 T8 X
System.out.println();
! b$ F" W9 b' e
}
( p6 B$ u- E# [$ |- {
}
! z: H; @9 u+ ^/ i6 x
}
3 v( g2 t+ [ D" n
. C2 B0 q. {+ P7 L4 ]& ^& q' U0 Q: d
. a+ {! t" w, N6 N- {, m3 f3 p
TQC109
7 Z& r! a7 t- `( o3 K
public class TQC109 {
! ]6 T: T; |6 i4 q" f' k
public static void main(String args[]) {
( }8 I: x0 }8 t4 P; K) l1 k
int r;
* L/ O; H7 b) e8 V7 ~& {- u
r=(int)(Math.random()*100+1);
- Z- b- U7 X( G, m8 R, H
double area = r*r*Math.PI;
7 @2 i ~9 Q0 t$ {! K" g, h2 m2 g
double vol = r*r*r*Math.PI*43;
8 S, v1 x1 L; D$ R# n
System.out.println( "隨機產生的半徑為:" + r );
9 g6 G% c0 g% C; [6 w) E7 n
System.out.println( "計算後,直徑為:" + (2*r) );
! Z! J4 T6 J% L, j3 d
System.out.println( "計算後,圓面積為:" + area );
$ s: F; O1 Q1 t. _- \; ^; u
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
# @4 w( ]" s3 q$ M5 B* }# z
System.out.println( "計算後,圓體積為:" + vol );
7 p) M) \# c8 }/ x4 P
System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
+ e2 Y) F, j* e7 C
}
& K/ I+ ?) o @8 L8 g
}
' U8 w2 j8 G# {- C! {- B2 h( _0 u
# L- Z. R, D& P' f, W) O5 Z8 K/ D
# V3 F5 I z/ _) {$ p4 p4 l
TQC110
3 C- Y! h, r) Y
import java.io.*;
- q! y9 c5 i& S: O' S7 W6 q
import java.util.Date;
& V& ~- O9 L- x) @) }- B
/ r# A9 X0 j9 K& @6 p) f) W
class TQC110{
; C" q4 t2 w# W, e. u f4 g. v
String items[][];
# N8 h# t, Q! g' P# v: E. m2 B5 K
long start, end;
5 W" d. d2 L; C: K( D- u
Date d;
0 V+ | `* r: G5 x) Z! c
BufferedReader br;
2 y% Q8 A7 h! j& Q8 M' i" Q. ~
' F, `* D! u. C0 d1 W
public static void main(String args[]){
; Q5 s3 W. E% t
int total = args.length;
* f* [. K: r7 G4 W8 B6 H: i
int pairs = total / 2;
% V! @4 d/ T5 X1 e6 P
TQC110 tte;
2 s0 v# g4 ~& t
if(total != 0 && pairs != 0)
. U P/ i8 P7 }: l" |
{
" L& w- l4 G+ V5 Q& z Q
//get value from args..
; g' T1 I, W4 ]6 S
String[][] tt = new String[pairs][2];
/ V a9 l$ C6 ]" [0 j, |
for(int i=0; i<pairs; i+=2){
8 g, I2 }% G$ T+ k2 E6 z" E
tt[i][0] = args[i];
# z% ~ u' Y' g0 e
tt[i][1] = args[i+1];
0 _+ ~/ z1 x7 K) X0 F; H6 o5 X Y
}
4 g- N! o$ M4 g
tte = new TQC110(tt);
' G- i& J4 B" ~6 ~/ J* ?8 z
}else
! g, z( h% c) `" `
tte = new TQC110();
g5 t7 l7 ?( t! l7 X3 g% z
tte.start();
3 w2 B7 Z- A( m7 q2 C, o' y d
}
% M6 k, d( D# A _
: [+ }% P0 F6 ], c" F: m
TQC110(){
4 l* Q+ Q+ i# k7 R! [4 s# x2 `
items = new String[5][2];
3 p y; n9 f+ B7 ~. L: K$ p
items[0][0] = "電腦";
. i- @/ g, J" A( {* r0 t! h; V! b
items[0][1] = "computer";
7 i- R) R- {* j8 S
items[1][0] = "資料庫";
/ _% e+ \4 t1 m9 K- F% ]8 n
items[1][1] = "database";
/ Y# e, F7 T8 x
items[2][0] = "語法";
& Y2 K8 ?; O5 ~3 ? p: R+ X2 K# F
items[2][1] = "syntax";
$ H; U+ m( R' F
items[3][0] = "學校";
9 E7 F2 k- Q2 y. c
items[3][1] = "school";
9 i3 [/ Q- d0 _* |) j: o
items[4][0] = "假期";
5 B8 T6 P# Z% e$ H4 r1 e
items[4][1] = "vacation";
/ D: [7 w3 ?6 U# V# v
//make default value
+ n x/ g0 h Y! e+ O% E A
br = new BufferedReader(new InputStreamReader(System.in));
0 j% J& _9 m0 y9 c
}
/ n( G8 N5 S5 y5 q9 q- W7 F
! w# n J/ a8 O
TQC110(String[][] it){
/ d0 U! t( g0 Z& `( x
items = it;
" [" c$ w/ ^ |3 l0 k4 a
br = new BufferedReader(new InputStreamReader(System.in));
# g2 H- F3 W# j/ T
}
% s( x E; i5 Z O& [4 H2 z3 y, C
' G# ~' Q. A) ]
void start(){
9 C: {* i6 R" h F6 t1 ]
String ans = "";
. P8 E) Y. o8 D: Q( _
int correct = 0; // 計算答對題數
+ j! T! r9 [/ e% |; u% V6 w
d = new Date();
" u0 A9 ~: n0 o( h' U' S) q t0 o& {
start = d.getTime(); // 開始答題時間
8 c, |0 F% _% S- x6 C/ s3 U
System.out.println("請將題目的中文詞彙翻譯成英文單字!");
% X+ q2 Z3 {+ ^5 p! D5 s3 M
System.out.println("輸入英文單字答案後請按Enter鍵:");
7 J+ B8 G6 Q" s- c. l
System.out.println(" ");
6 I9 W6 ?+ N5 h5 W
for(int j = 0; j < items.length ; j++)
+ h1 _4 o u: u7 v' ]
{
. @5 x/ Z! z4 j$ M
System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
, i6 b- _/ A- W6 G) c: c3 Q- N0 L
try{
) H) ?$ z. J9 u9 f' ^
ans = br.readLine();
2 y* I/ F# `/ V( `# X
}
9 d( B/ a/ a- Y4 N. V- U
catch(IOException ioexception){
+ ~- |; z& u; f! `
System.out.println(ioexception);
( I$ I4 j/ l) u2 ^, H5 i" g
}
) y5 F* ?4 Z4 f( T D. i
if(ans.equalsIgnoreCase(items[j][1])){
' t1 x6 ?+ y* G, E: r( H [" D
correct+=1;
0 Q& z0 f2 D8 S4 B1 m
System.out.println("答對了!");
4 p2 D7 R2 r& U; n
//count correct
% K4 ~! N. i! @% Z1 i) T+ D9 N
//ouput correct message
! h/ y. ^2 G" {# u: [* e% f' z
}else{
5 d5 w! Y! w8 a6 S
System.out.println("答錯了! 正確答案是:" + items[j][1]);
; y2 v1 U4 P# k* ~/ z6 M7 N* W
//ouput incorrect message
5 W; {1 |: s7 G& _, G
}
* m0 W% S+ z: K8 Q7 x0 E D
}
, S0 k# i: _/ O
+ {6 H `, C2 U4 o( P+ s# I
d = new Date();
' t: M) \) ]2 L
end = d.getTime(); // 結束答題時間
6 t0 f( R/ q6 {% V3 ~0 `+ u
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");
# }- L0 m1 m7 j; B2 r5 i, ~' H2 J% i$ B
System.out.println(items.length + "題中答對了" + correct + "題");
/ C) h+ T# h( {& W& S9 I! J) j
}
3 u3 |: p& U" N
}
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2