返回列表 發帖

TQC107 ~ TQC110 答案

TQC107
( p, v5 `/ w. U7 n9 e# E9 \public class test{, l  S: N# M7 _: f
/ L" D% P# D5 W5 H  L
        public static void main(String args[]){
8 f' h+ X6 e" R# b& W        / a: @  G! U5 ]: [6 q$ ~+ ^3 ]
                //0 1 2 3 3 e0 C) H0 D- v
                //1 1 2 3- y# S2 G/ x5 X# M
                //2 1 2 3
, Z, {6 f- Q6 `, M& ^& _7 B4 x                # r% ]0 F4 L! }: F
                float tot = 0 ;+ [: p# \# C5 T: f" K. p
                for(int i=1;i<args.length;i++){
/ c+ ~9 O* P7 m                        tot += Float.parseFloat(args[i]);
9 W& H: D5 j. P8 J; \( Y$ s6 l                }
, C) z( V$ q4 b9 x, T2 P9 k' P* U7 B                tot /= (args.length-1) ;
% f4 l, {* V* M/ ^+ i& w               
$ t( R$ i! z1 G, r3 t3 k4 I                if(args[0].equals("0")){6 U8 T; k# _4 S3 \, A6 c
                        System.out.printf("平均值:%f",tot);" a; d2 g$ z5 K; B
                }else if(args[0].equals("1")){; t: q+ r, H3 m: A. b/ F
                        System.out.printf("平均值:%.1f",tot);* K2 y/ C8 ]) {( u
                }else{" Y& ]( G8 d+ n
                        System.out.printf("平均值:%.2f",tot);
3 D, L/ h  z; n% ~7 R! ^                }& e& Q# e! N, [9 o
               
  H4 G3 R, N7 `                9 E  S) g: Y: K2 O% @
        }4 Z/ e- {/ R8 Z( f2 P

! y6 R. M& R& _1 h. M8 ?" f* Y' L
}4 `, S# b# t# {2 ^( R; ~# b: [: ~
TQC108; r* }% O  u5 I" R5 U# J' q
import java.lang.*;
4 ]" @6 X# U4 c; n/ K* O
: S/ q4 @& }6 w  X3 U$ i( Lpublic class TQC108
+ [9 K* u( {2 @1 a{  g- A# |$ _* K( x) z
  public static void main(String[] args)                                         
3 K3 O* `( U* T: c! G0 ~# @  {( |. Q1 |% w4 O6 ?4 W0 W
   for(int i = 1 ; i< 10 ; i++){) u) }: i$ k4 F! s) R$ F
      for(int j = 1 ; j <10 ; j++)4 ]' t% ]" i( _! A+ Q
         System.out.print(""+i+"*"+j+"="+(i*j)+"\t");  T5 U) v3 h- }- n" `  x1 W) D+ F
      System.out.println();
6 U+ B5 @1 m# Z+ D   }) Z; I* t$ U" X% t" E' I) F
  }1 \; i) l9 D- M5 l6 h# k
}  L2 B- ^  @# L9 r
5 n# b2 V* X& ]! [7 m
( c' m9 Q1 q/ k7 T. P" }
TQC109
5 [: E" _8 W0 j1 a$ V. V3 P4 Vpublic class TQC109 {' ^7 N" x& S0 n1 X* T
  public static void main(String args[]) {
4 U) E  q7 [- H% G2 [5 P5 V9 v    int r;
1 |! _& T, d- X  v/ @   r=(int)(Math.random()*100+1);
# l/ h3 Y9 c( m8 S8 Y# s   double area = r*r*Math.PI;
0 |1 |9 j& ]0 u, C8 w% m* `   double vol = r*r*r*Math.PI*43;
( n* ~8 X. @' R   System.out.println( "隨機產生的半徑為:" + r );1 P/ v  |: a9 W
   System.out.println( "計算後,直徑為:" + (2*r) );! P, V! A" K) c$ G
   System.out.println( "計算後,圓面積為:" + area );
0 m# w! ?+ p( w9 W+ g- \9 n   System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);, w+ _3 u. g' [! P% X
   System.out.println( "計算後,圓體積為:" + vol );: J7 S3 l- l2 y7 X: L
   System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
/ Q  U- O8 h* ~( k$ b8 C( R+ _  }
0 D" I% N& ]8 l3 U5 z" W) @}% z  p* `& ~+ b2 Q& k

; H. Q- I% C6 R: G $ O* W! t9 o1 {0 R2 P7 S; T2 R. f! C
TQC110   ) d! V5 {6 f- F# v
import java.io.*;% X3 U4 t2 m  h8 \7 q4 _8 n% k/ V
import java.util.Date;$ ?. W1 x& y  [% `! b1 Z

" ?% E9 z% L! P    class TQC110{
9 q: {6 |9 T0 ]  V, x        String items[][];
7 `, z7 Z- q& \: r; H7 w: c        long start, end;
3 c" i/ q0 G' Z1 T; F        Date d;: l, h8 I; q" l3 @# p& H
        BufferedReader br;
( x. @) V. b; k1 c$ O) f7 h5 ?, r3 h+ L. p
        public static void main(String args[]){; S6 _/ w+ X0 i2 w' M
            int total = args.length;
8 `0 y- P  U+ [: [1 M            int pairs = total / 2;. ]3 o7 G/ r5 w
            TQC110 tte;: N) U9 {9 j/ N) \; H3 W
            if(total != 0 && pairs != 0)
- W! k8 P6 i. {% N. Z# T            {! @* E. B2 ~0 z, O( ]6 m
               //get value from args..
2 X' T( _$ \7 D$ b3 @  k3 ]- k              String[][] tt = new String[pairs][2];6 v9 g; q* O# ]1 s
              for(int i=0; i<pairs; i+=2){. c- c0 z9 j0 H) V4 l$ \
                      tt[i][0] = args[i];
$ |0 O4 E9 w6 p5 ]" t4 O+ J+ e1 D                      tt[i][1] = args[i+1];+ ~  h' H9 g/ N) R' U, H( u
              }6 g, a9 g5 E9 H+ T
              tte = new TQC110(tt);( i; v( S/ C6 R  G7 L8 A4 i2 U
            }else  W& I6 g5 a: ]6 c2 S
                  tte = new TQC110();# |% u7 \! A. K! z% U0 o$ X9 M
            tte.start();9 f# D# J: W3 ~; m; r1 X
        }2 e1 I+ R( k% s! p

. U7 J& t/ O3 ]        TQC110(){
" t  }, u$ U2 G+ O& p2 s) ]: q+ ~2 m            items = new String[5][2];, E  T7 k! U3 x& K- k) K+ j2 _
            items[0][0] = "電腦";
! V# g/ J! I0 p" o* _            items[0][1] = "computer";
6 E; R: R( w0 D$ E8 Q            items[1][0] = "資料庫";% t. D- h# M0 X3 E! F
            items[1][1] = "database";
4 P% L7 P% F, H7 m3 e5 Q8 w+ U( V            items[2][0] = "語法";: d% A" L( h5 J0 M: b. E! r, E+ T
            items[2][1] = "syntax";
5 V; |' M) h" t+ S4 |9 H            items[3][0] = "學校";4 N' _1 ]' J* Y# {2 D
            items[3][1] = "school";2 r) J! G( F  e$ ?5 b
            items[4][0] = "假期";* _; H$ {9 e" q+ ?  V6 L5 e5 x
            items[4][1] = "vacation";* U0 z: e2 d# D) T( \$ m
            //make default value
& L* l5 k2 Y, m  h  E6 g& Z) n            br = new BufferedReader(new InputStreamReader(System.in));
% u/ c8 J' E6 t/ l) X/ |9 u        }
1 m% l3 F% U% u7 O9 T) f# P                  
+ h+ s: m3 U- q  w0 L$ H        TQC110(String[][] it){( H7 I1 d4 f) J1 A4 o( P
            items = it;2 s/ w4 n. V  H8 |/ r
            br = new BufferedReader(new InputStreamReader(System.in));
; ^* t5 |/ G. v        }
; ]7 t* W. h0 P9 f$ u                   1 H/ K/ {+ d& B! _6 W* U
        void start(){
0 N2 h0 \* R8 @            String ans = "";% x# V/ b- r# l4 z
            int correct = 0;      // 計算答對題數+ W2 M- ]1 M5 n# S: H, m" u
            d = new Date();& y* S. Z$ ~1 r7 `, Y! n- H
            start = d.getTime();  // 開始答題時間
& p9 R; W) A  s            System.out.println("請將題目的中文詞彙翻譯成英文單字!");
5 D2 H- @7 ?: |1 H            System.out.println("輸入英文單字答案後請按Enter鍵:");! J; {: \* t9 F* @( e, Y* y  ~
            System.out.println("           ");: ~' r7 F; \6 r- V& L8 L" @6 c; o
            for(int j = 0; j < items.length ; j++)
$ \* }, b7 q& j) Y; Y, ^, N            {
* P, I4 H; P& v' g: f3 m) d: ?                System.out.println("第" + (j + 1) + "題__ " + items[j][0]);, Q; p; C# m& J2 Z6 _
                try{
$ c3 `. P& R# }( ^2 d: N. r* Q                    ans = br.readLine();4 L, u1 v, M2 Y8 @% w0 E
                }1 E1 m+ }, c0 j! s4 X: }( p- i
                catch(IOException ioexception){8 r. s! U: {5 u4 C, P2 x
                    System.out.println(ioexception);8 `. t2 ]3 P7 u5 b" z( h5 ?
                }
+ `# Z; {, G" p% k+ O& w                if(ans.equalsIgnoreCase(items[j][1])){4 q9 P- S8 b, c5 F- m" j; ]
                    correct+=1;6 c# x, P4 j0 N( p8 F
                    System.out.println("答對了!");6 {" h: @" _! k- c' Y8 O; N6 O
                    //count correct
/ o( a& V4 a$ k- K                    //ouput correct message
$ b$ V: r' |1 D2 d3 e  x9 \: R                }else{
" D) Z, `% {6 F9 F                                System.out.println("答錯了! 正確答案是:" + items[j][1]);
' o) \( c' c$ v1 l6 Q                    //ouput incorrect message
. E' w& x; X+ x+ N( o: H                }
& S8 i7 q' |# X" _+ U8 }            }  g( T3 ~, n# t) z/ Q5 s

2 _; e2 P/ Z' H6 O! C5 |. h" w. m            d = new Date();
$ D" \# a  e  H: ~! ]& r7 b# \            end = d.getTime();    // 結束答題時間: l, c8 `6 G5 m3 z2 }! d4 s
            System.out.print("你使用了" + (end - start) / 1000L + "秒,  在");3 p( t) o+ X$ y/ _: |
            System.out.println(items.length + "題中答對了" + correct + "題");
) P( ~5 F$ j' Q. B  |        }
& a) f6 [  q: ^    }

返回列表