Board logo

標題: TQC107 ~ TQC110 答案 [打印本頁]

作者: 許逸瑋    時間: 2012-4-8 20:06     標題: TQC107 ~ TQC110 答案

TQC107
; W6 t( J1 V/ d: O( Y; m0 mpublic class test{
- V( @. G+ z! m% X. d! `, r4 M2 ]2 _2 e% y/ a- s9 F& j1 d; r' Y8 m
        public static void main(String args[]){; R( b& j: x% N" d  J+ E
        
- B% T& ^) Q9 K1 C4 i! R( w! K& g' J                //0 1 2 3
2 ?% l* S" x( o' E* L3 A2 \2 W3 }- S# I                //1 1 2 3
' x- _2 ~! R, ]6 T                //2 1 2 3
+ ~  c# S$ {8 j+ B! U  K                ' D; m4 R  o$ n. L
                float tot = 0 ;0 T9 S7 M3 U9 |, V, R
                for(int i=1;i<args.length;i++){0 {  a" }& D. g& ^& H
                        tot += Float.parseFloat(args[i]);& |+ g2 ^5 q) L6 h8 P* T8 j! \
                }
) H9 O/ w3 T+ V; ^, ]" G. C, ~                tot /= (args.length-1) ;! o# P8 m4 D6 L$ j
               
# ]5 \$ c) _4 p9 H- K                if(args[0].equals("0")){1 f. b8 c& b8 F4 k$ F
                        System.out.printf("平均值:%f",tot);
- v: d  v* {- e4 ]$ c                }else if(args[0].equals("1")){
5 h7 z& I4 O' t4 O' a& ]4 i                        System.out.printf("平均值:%.1f",tot);; w* u7 i7 y2 m% u
                }else{6 A) R: @$ z+ \1 {: {$ g' x, w
                        System.out.printf("平均值:%.2f",tot);; {6 k# Y  T2 S3 K4 L
                }
; l( H! O6 f$ c2 @+ D4 c               
* U5 ^/ [/ n8 U" r- G( ~               
! K5 ^& p0 N% `4 ~        }! q% x0 K: ]3 N, ]% [0 W' x4 M! F

* L$ H8 Z. i1 G* q
8 R1 e! v4 V6 h7 `5 C}
2 d  D! ?8 y: [5 I/ P1 e2 E: jTQC108; X/ ~2 e7 \2 U$ R  g
import java.lang.*;
6 o' u) c& P1 {+ N9 o$ Z, b. ~0 }8 s. [  l6 w0 r
public class TQC108* l& S: K2 j2 I1 E  H8 s
{- M% x& H' Y- k& p0 }" S: @# m
  public static void main(String[] args)                                         
4 J/ l# w) }* l1 e6 G$ ~+ m  {
+ X/ e5 Y; U5 i& `! y1 ^1 J   for(int i = 1 ; i< 10 ; i++){& W: }0 A7 R4 P0 T, H
      for(int j = 1 ; j <10 ; j++)7 y. B/ q; x- o5 @# x1 w$ O
         System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
- c6 F# ]& a' f. E  E      System.out.println();
6 Q+ ~( s8 `% {3 ^$ i# ~7 S   }/ b% I. P% e7 H% j
  }
: k6 d3 I2 ]% N4 r4 ^1 G}
; \3 N+ C' q' G: `8 B0 G! U& [$ h' ?5 F0 R

; j. i* e  J+ B$ o1 \( |$ Z; gTQC109* G% k! k- J' g) _! |9 C4 i( L
public class TQC109 {
; V5 e/ A% j, ^' J3 M  public static void main(String args[]) {9 n/ p3 g9 ]+ n' @
    int r;
, K0 E9 l# _9 g8 x& {   r=(int)(Math.random()*100+1);
, M. h$ \. U0 `7 k% T3 r   double area = r*r*Math.PI;
+ J% w9 G, m' J& ?# y* w& J. n8 r( V   double vol = r*r*r*Math.PI*43;
5 Q6 H" v% W! w: A7 m/ m   System.out.println( "隨機產生的半徑為:" + r );. |+ Q5 V' G9 H6 X/ o2 A' c, E
   System.out.println( "計算後,直徑為:" + (2*r) );
, R5 m5 U! a9 a( L& k! b) C   System.out.println( "計算後,圓面積為:" + area );% C' F. \' i- C3 |0 g) J8 k, a
   System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);  D5 h1 p4 b1 P6 b: V" v! x
   System.out.println( "計算後,圓體積為:" + vol );1 u% c9 j" r2 @- t0 x
   System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
/ k0 d! y( i" b1 X9 z  }  U1 n) P9 ?; e: n* S, a
}& J3 b/ c! p: w% f
/ Q- T% d, A/ b2 W0 ~& `
- Z- w2 ]+ X1 }5 z' u
TQC110   ) r3 u. Z6 x8 r& O  Q, g- r
import java.io.*;" L) b; p) M5 k7 L
import java.util.Date;
* V# L( a% W' d" }* w
( u+ E8 Y/ J; }5 |- f# t    class TQC110{
. |/ w. q9 j3 h- M; p        String items[][];
* q4 d7 z8 ]6 g! }        long start, end;: o- j/ }' @6 k$ r5 S
        Date d;, u" P* `0 A- p3 l. e- x  f
        BufferedReader br;' w- b% n3 \! S+ n+ Q( l, z

9 f8 T7 G  n& B0 ~& g4 L9 Z& [        public static void main(String args[]){3 W6 S7 U/ @; e) ^* Y; g+ t& x9 l
            int total = args.length;" D$ c( k: w" @5 I2 L: k
            int pairs = total / 2;# y' d9 N: V6 T4 C: C9 U7 O
            TQC110 tte;  i2 d- O6 I" ]4 \' a
            if(total != 0 && pairs != 0)
* P( f( m" _! r            {  P, g# v# Z- r' t+ F
               //get value from args..- K8 I; o* h% R/ J* l& F5 Y! \
              String[][] tt = new String[pairs][2];
' _8 E" b+ N0 M$ i2 A  ]              for(int i=0; i<pairs; i+=2){
2 J* q: R, z7 h                      tt[i][0] = args[i];
. q; l) u8 ]$ P                      tt[i][1] = args[i+1];$ U. J4 S5 r! r  V/ r$ s6 S
              }
1 Y' y- C5 Y( M! S              tte = new TQC110(tt);
0 a( u  C! z+ \1 P            }else
% T8 t* H" N) j+ x2 X                  tte = new TQC110();
7 o6 z: O5 K* N9 v3 B: @            tte.start();
1 a# K3 r- }* B        }8 i6 \& m  y& H( X: q
5 d* N/ L, S8 \
        TQC110(){, q( D5 ]5 t  ^* z2 N  A: ~; z/ s
            items = new String[5][2];
; e' A2 m! Z2 }# T# B0 }, Y* T7 m            items[0][0] = "電腦";9 _/ @7 }1 ]$ V" |- e( {. b5 r
            items[0][1] = "computer";
1 E: U$ z* k9 M5 O/ W3 i            items[1][0] = "資料庫";  o3 F! m# f2 f
            items[1][1] = "database";7 m6 H/ f$ |8 t/ {( R, K) x8 K: }
            items[2][0] = "語法";% v  G& P, S7 m4 @" {7 f* C# R
            items[2][1] = "syntax";  p& P% N2 \2 d8 K3 K9 Y+ u: b
            items[3][0] = "學校";7 c& }: }3 P/ Y# M. `
            items[3][1] = "school";/ D( g9 p3 d1 ^
            items[4][0] = "假期";5 \1 ?* v6 Q1 ^! ?4 p
            items[4][1] = "vacation";
* w! ]/ [" E% ]2 Q0 H+ u( o            //make default value! s) R' ]  O4 i; o- z
            br = new BufferedReader(new InputStreamReader(System.in));: h/ y' y5 ?9 d4 A! Y- R3 r6 P4 D
        }
% g! P$ e2 [2 L3 i7 [+ ?                  
) c, f& V2 n' K2 f! S5 u' ~- @  L        TQC110(String[][] it){
0 _( R/ o5 C2 X9 i3 D5 I8 u            items = it;
, Z& U# E6 _' {            br = new BufferedReader(new InputStreamReader(System.in));
5 k0 k" E) D: ^) o) A  @8 v1 N        }
) p: h% ^4 f& z- ?" T                  
9 p- [6 U' _3 G) N3 ~9 e* q' [3 N        void start(){& U9 D/ [( C1 R1 s; x2 Q3 {- d. ?3 R  P
            String ans = "";
2 {2 j- q! ?  s            int correct = 0;      // 計算答對題數
2 I, z* N- Q: o; g9 I            d = new Date();
& w4 ~$ K2 ~! n# a. B8 J3 U& v            start = d.getTime();  // 開始答題時間7 ?# [4 }, k8 R4 m' C+ e, M
            System.out.println("請將題目的中文詞彙翻譯成英文單字!");+ p  q( w5 A3 ]. p
            System.out.println("輸入英文單字答案後請按Enter鍵:");, ~# X  E) s# p  I& E5 F" V
            System.out.println("           ");
. e5 D4 t0 X; Q4 j" m* R            for(int j = 0; j < items.length ; j++)
- a4 C9 Q3 D' ~% W6 a3 j# y            {* k& i' A) x, c& p4 K
                System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
% [8 \: U( `6 `                try{' W+ x' w* \1 j3 Y* u4 I0 _1 |
                    ans = br.readLine();
3 [9 I) c* F3 @& Z  w                }5 M9 D) M! X5 L, j
                catch(IOException ioexception){
: T5 B' j" w! s' Y  o, \/ O                    System.out.println(ioexception);! E2 O9 S# v1 y' F- o% A- r" s
                }
$ g% r* }) d7 T5 l                if(ans.equalsIgnoreCase(items[j][1])){
5 J, `+ ^: s5 ^8 c" J8 f6 e                    correct+=1;! M% ]( _' s( q" w# u/ }/ B
                    System.out.println("答對了!");$ U( Y+ d. J  v& j1 `3 ~# `$ D
                    //count correct8 J% ^+ g( }: G5 p% d5 l
                    //ouput correct message5 U  I$ W) _5 n( ~
                }else{
! g* t+ r; V& A5 x* l8 Q                                System.out.println("答錯了! 正確答案是:" + items[j][1]);
. {- M7 h9 B# ^1 i! D) [0 Y+ B                    //ouput incorrect message
% ^0 p+ D) T: r) c1 {( N% r                }
5 _+ t: Z" j# H            }
, C" t# W" k4 ~
: o8 j2 c" N& B+ V2 u            d = new Date();
, l, n8 @3 R6 l1 @! a9 h            end = d.getTime();    // 結束答題時間
: r, E' {, a3 v$ U5 G( C( F            System.out.print("你使用了" + (end - start) / 1000L + "秒,  在");8 T3 K  J& X, z9 W
            System.out.println(items.length + "題中答對了" + correct + "題");
. p9 S+ |* U" k, Z: t# f+ e        }, f! x4 I/ W7 P7 Q6 i) S
    }




歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2