返回列表 發帖

TQC107 ~ TQC110 答案

TQC107
% T2 H# ~( w/ Z% Y+ fpublic class test{4 G7 R/ A. |& j1 ?
$ S1 Q' C& L/ i7 D! b
        public static void main(String args[]){8 h4 B- T# ~, o- H  K* L) q
        
5 L0 Y+ ^$ r( {$ g6 t                //0 1 2 3
7 u$ b. R# b. @                //1 1 2 3, i! @- O9 r( o* d+ _9 G. l4 ~
                //2 1 2 3
2 U8 Y6 R4 v% l; {' [: N               
3 {$ o9 M1 }+ _4 L9 G                float tot = 0 ;
. P, S, e- y' t$ z2 s                for(int i=1;i<args.length;i++){' L" E; S7 h3 ]# U
                        tot += Float.parseFloat(args[i]);0 ~4 q  p% g6 i8 m( J6 m: s
                }9 a% I$ ^+ I, ^, T3 |; b% c
                tot /= (args.length-1) ;
% l! e7 o, r* {, G& ~' u0 O" h               
* C. ?5 L8 k) i; R$ C, C% o                if(args[0].equals("0")){
+ s3 v, ?/ Y3 _2 k                        System.out.printf("平均值:%f",tot);
, B* c7 |2 F6 r* |4 Z& h                }else if(args[0].equals("1")){( Q( b$ p& d8 R; V& n
                        System.out.printf("平均值:%.1f",tot);
" h- L6 r7 \, n& Y! n% F5 F0 a1 v                }else{
( {: C9 D& I/ D# o$ V                        System.out.printf("平均值:%.2f",tot);! E2 j7 }' O+ P
                }7 c4 r! u4 A9 P
                ' D2 _1 ]* V! Y
                7 e! V7 A: e) M2 ^9 Q8 u6 }0 f) ?
        }- `+ v# a% d0 e* X2 p  p3 r
# A2 m+ l* t  C

  U  X6 _! Y" {}
( C  Q5 F- P7 m: B% VTQC108
1 G$ f$ K6 F8 a" ?import java.lang.*;, {/ o1 s4 }! U" ?5 k
3 i  v- ?8 r% f+ \+ y, K  c
public class TQC108
/ `3 \$ f8 q( o{
* f: V3 v9 o8 n- D  public static void main(String[] args)                                         5 P: i1 p: b  F& l4 j
  {- f7 E8 N& W8 _
   for(int i = 1 ; i< 10 ; i++){
# i2 @' k4 \7 q& q) V      for(int j = 1 ; j <10 ; j++)
" P/ Y0 P' U. w* ?! P# L1 Q1 x9 P         System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
, A7 y5 ~/ s: P& f9 Z2 M& T      System.out.println();
( m1 n' k+ @3 Z. g( x   }
) O; n$ y% o+ i/ Q+ O  }" Q2 Q3 h# e8 y
}
  i8 t( u3 i) e; ?1 ~. j
; ?0 B9 ?' k- T& A- L
+ r9 u# D! x3 X  b" hTQC109
1 e; b% y8 H. ^1 Kpublic class TQC109 {
/ \- G7 Y% b3 x# D6 q: X  public static void main(String args[]) {
: z7 n0 ]1 z0 A    int r;
0 I- H1 @. _3 C2 B( Y; J  G   r=(int)(Math.random()*100+1);
2 ~9 ~) i0 b0 r0 A7 f2 a   double area = r*r*Math.PI;
& Z+ T# m7 ^3 b% A) `6 w3 B. ~. H7 V   double vol = r*r*r*Math.PI*43;1 u/ Q( f# z4 p: R% k2 `$ `
   System.out.println( "隨機產生的半徑為:" + r );( R% q1 E2 f2 D7 y' ]
   System.out.println( "計算後,直徑為:" + (2*r) );
( i+ t* g( Z/ X8 N% t4 _6 }   System.out.println( "計算後,圓面積為:" + area );" f0 O/ ^: v: u7 E9 S  m" h
   System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
# z, q/ x: Y; v' J   System.out.println( "計算後,圓體積為:" + vol );( ?" K+ B% A0 y* J" I9 H
   System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
* e( U- [4 i+ S5 w, u  }  M+ A- j3 h3 }% k% F7 a/ L8 D
}# z3 h6 ?/ k+ p3 g9 \$ R

. ~9 h  E; K: Z: l 0 E6 I* z5 V! M. w+ t
TQC110   
( w" w9 @) G5 E. bimport java.io.*;
8 x& x9 C! S" i( B! Q0 b7 Y6 @0 [: Oimport java.util.Date;
1 R/ ^9 A' `  k6 Y# p. A; H
2 H) @4 _, j# U) _( x3 H    class TQC110{2 @2 g) K; w4 W. B8 s. V: ~* F+ ^
        String items[][];
) n, }$ W/ l2 Y' E" r* W) f        long start, end;3 d2 ~8 z; B3 T: r7 v4 r
        Date d;1 z& \9 ?: K+ b* ?
        BufferedReader br;
4 v1 s5 i* G4 C0 ]0 o5 E2 x; B( Y, O/ U( v
        public static void main(String args[]){. |# S+ M5 ^; M/ M+ n! i: z5 A. v
            int total = args.length;
# \9 _+ q3 O/ I# y- U# u2 [            int pairs = total / 2;2 s$ h9 v5 U- n9 g2 Z; n
            TQC110 tte;
( [  y, Z2 Q" X' z            if(total != 0 && pairs != 0)# f7 ?+ v8 W& {, ]6 d: }
            {
7 U) }2 k6 V  j/ @/ }& t$ b) Y               //get value from args..& C" V  {! D5 f% w2 ?
              String[][] tt = new String[pairs][2];; k: y5 R- A: E5 t, O/ l% K5 o
              for(int i=0; i<pairs; i+=2){
) |9 q7 p  r) W9 r5 A# A, M( q) ]! h. `                      tt[i][0] = args[i];5 }8 O  @3 H& }# n0 {
                      tt[i][1] = args[i+1];
8 u3 V2 U! ~2 @$ n9 s! ]: ]              }
# _/ f+ ^; k- v! d! l              tte = new TQC110(tt);
. z5 u- M& X" y( e, u. B            }else
+ [; X7 b0 B- n, L                  tte = new TQC110();0 P% ?1 M& j. f( e0 z
            tte.start();4 i9 u& L- H! q1 t) x% z# q
        }7 S  A% _) t- _$ f
" r" U  t' X% {9 ^) p
        TQC110(){7 Y. w3 Y; U( b8 K1 M' S
            items = new String[5][2];
! ^- ?# O! c- O, H2 m$ v            items[0][0] = "電腦";
: ^5 Y% K8 ~; y0 T" w% Z            items[0][1] = "computer";; ~8 N8 j# i. [  I$ K
            items[1][0] = "資料庫";7 O7 ], g2 h- f
            items[1][1] = "database";
0 u3 }- E. R2 g8 v            items[2][0] = "語法";+ Q4 x. U6 |: ?5 j
            items[2][1] = "syntax";
5 O4 I# J: K0 D7 V            items[3][0] = "學校";
# ]# r, f6 e/ ?            items[3][1] = "school";7 G+ \" W% a: d, p7 f6 j# ?
            items[4][0] = "假期";
* O2 U( b5 o  l( u) u$ U, A            items[4][1] = "vacation";$ d7 ]1 F* m% G3 k+ [
            //make default value$ X- D3 q" J! f  E' S
            br = new BufferedReader(new InputStreamReader(System.in));3 {) ^9 @+ T5 ~+ v; S
        }
* f: _1 b7 h8 U8 o, z8 j                  
' j$ n$ p, [! J7 `6 x3 T5 `* @        TQC110(String[][] it){
+ f4 s; ]( Q+ W7 A# X& p0 K, }$ z            items = it;  t6 |- t" v% Q8 T
            br = new BufferedReader(new InputStreamReader(System.in));/ V, T+ t2 L4 v, I1 R6 V
        }. c4 U) p" Z# N; h6 _6 a9 ~* a3 A
                   2 f; K, H. _( o( H( P1 q* E  B( L
        void start(){
- i: a9 h/ V% b1 ^0 v* O            String ans = "";
" W* I' L3 g% d  p  s            int correct = 0;      // 計算答對題數
6 _+ ^0 O  B6 [: O5 W* h            d = new Date();
# j" _7 X; K0 ?) V2 W            start = d.getTime();  // 開始答題時間3 R8 n! s. x- [7 A6 `
            System.out.println("請將題目的中文詞彙翻譯成英文單字!");
, z/ O2 u, a, X: b) Y' d            System.out.println("輸入英文單字答案後請按Enter鍵:");( W( H  }0 ?4 n$ }
            System.out.println("           ");
  L# S( a% ~' `1 D5 I            for(int j = 0; j < items.length ; j++)# F8 Z/ Q  R9 ^# X, G
            {
8 y, h+ y7 _" w# Q" ~                System.out.println("第" + (j + 1) + "題__ " + items[j][0]);0 i7 `8 |8 @% d2 r: R
                try{+ t; N/ j& J% ^, c; P3 f) @& ]" P
                    ans = br.readLine();
; i9 y% K' a. w8 U: p8 K: ]                }7 x5 R; {3 {9 V% S" H+ Q* l, ]# @
                catch(IOException ioexception){0 i* Z' t! E9 y6 d. t
                    System.out.println(ioexception);
) x$ k4 C3 h' q2 ~- r                }
5 ~# d1 e$ _9 C/ O  x                if(ans.equalsIgnoreCase(items[j][1])){
) p- y8 z  J7 o4 Q" v6 s                    correct+=1;8 A4 _  ?2 M% _( z+ e7 f
                    System.out.println("答對了!");
. A. f0 c; n$ z0 ]! V                    //count correct- ?$ |! \. E4 d6 S  i8 F
                    //ouput correct message- \& P& K8 t: j1 L+ R2 m) F
                }else{
& Q1 a: V/ B9 n                                System.out.println("答錯了! 正確答案是:" + items[j][1]);
# ~5 H9 @! z1 F# z7 R0 s1 f                    //ouput incorrect message
3 G; ?3 \: l2 Q: P1 I" t# W) c                }" E1 B( @* d( c" m0 U4 a: `
            }! b1 h# Z; ]8 k% u4 q( z
3 [3 i* E& i" R) ]
            d = new Date();
2 K+ |) |; O# i% v& e- w  |- K% u1 Q; w            end = d.getTime();    // 結束答題時間7 ^8 X% Y# \% ^- R
            System.out.print("你使用了" + (end - start) / 1000L + "秒,  在");
1 Q+ c8 I+ Y- w1 F. a            System.out.println(items.length + "題中答對了" + correct + "題");
9 E3 J% Y& h! M7 {/ B        }; _2 ?# O: y1 Y& G1 K* {
    }

返回列表