返回列表 發帖

TQC107 ~ TQC110 答案

TQC107
5 @9 T' r$ r' _# R2 {) Cpublic class test{
) |+ r! D2 V" `
& d( I0 d* A% Q1 C        public static void main(String args[]){
, e+ m8 k( V1 _) t        - I! n- }$ ~1 j' \
                //0 1 2 3
) _0 U8 i% R3 l1 r# Z                //1 1 2 3
9 u6 X; {; C* @" L$ d6 P6 t" f                //2 1 2 3
0 }: G3 e2 s" E$ ?8 d  A6 l, O                + Z. s% W" U2 h2 C. Q7 G! O
                float tot = 0 ;  H& k# X$ r5 i4 {- h
                for(int i=1;i<args.length;i++){
, f2 S0 g- o8 ^- Z& C2 P                        tot += Float.parseFloat(args[i]);8 \0 C6 X! y2 V+ @# S/ i( B
                }
5 S7 S. w- y3 {0 b# c8 c: {3 L                tot /= (args.length-1) ;
% ]6 a' n5 x! s                6 ~* H  R+ g) I7 T) B
                if(args[0].equals("0")){5 `: w6 i- ]) Y; V) o* ~
                        System.out.printf("平均值:%f",tot);
! x; @" v" B7 G: ~( I; W1 U) D                }else if(args[0].equals("1")){
5 R( D$ m) N2 G( a! V. I                        System.out.printf("平均值:%.1f",tot);
3 W( E: A# S0 ~( F5 G                }else{8 ^& ^& `! f6 g8 ], N4 Y7 Z* M
                        System.out.printf("平均值:%.2f",tot);
; r7 x9 P) y/ T; R                }) i- l/ B# e. {
               
* P" K8 X5 Z' f$ |4 Y                2 ]. e8 A/ ~' i2 n/ V9 W
        }
2 |. [: e# v8 l- I6 z6 Y. N3 g5 X/ E4 M6 _; l
2 r( A0 u# b- @
}
( n) I' W; n* A" XTQC1086 Z/ l  D! C+ c# L' Q6 W, \' @5 V
import java.lang.*;
! `, c# \' b/ s, F+ Z* B4 D
( f5 I. K. V( Cpublic class TQC108
8 l& _. G# E7 y" i2 G$ i{
& }% f" W/ H6 b, B  public static void main(String[] args)                                         
6 c1 h9 T. p) C( f' a0 _  {* L7 d; t! Z  s6 \
   for(int i = 1 ; i< 10 ; i++){+ g2 G+ K3 @1 h) r  ~& G4 |
      for(int j = 1 ; j <10 ; j++)5 e5 C+ b) X2 ]7 ~! u
         System.out.print(""+i+"*"+j+"="+(i*j)+"\t");! }( G" b- O( z9 E: o; d2 z! h8 H
      System.out.println();; i1 D% T% r7 S7 j
   }
# r/ O# z" w# T: P  }
. w8 G* W  D: W}' {) k) A: H# Z' Y
& M9 {; t2 D0 _& \7 ?

7 U& {5 `/ X. f3 KTQC109
, I& h4 b9 f; T' O; J- u3 n4 B; rpublic class TQC109 {' Z6 E3 q& Z! ~" j  ^, Z! I3 D5 T
  public static void main(String args[]) {
) z4 V8 f+ Q- |, h    int r;
& m# J( f  n4 A7 Z   r=(int)(Math.random()*100+1);! l8 j# L4 P6 M0 K* ]- D
   double area = r*r*Math.PI;
2 n4 p  E* r! ]9 `' s   double vol = r*r*r*Math.PI*43;
2 w& x. Q  O) }   System.out.println( "隨機產生的半徑為:" + r );
$ e% x7 Q" j& K3 N9 X   System.out.println( "計算後,直徑為:" + (2*r) );
* ?( p& s7 L$ S. T3 p2 C   System.out.println( "計算後,圓面積為:" + area );
! k+ P' j: i: y6 n   System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
7 d0 ?. m$ L( j/ L   System.out.println( "計算後,圓體積為:" + vol );
; v8 [, ]* k, t4 k* M9 D   System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);% ?8 U6 g5 f5 i. x" q. y- s
  }3 f$ _7 G4 @2 i
}
/ a- W. [9 v% l! }. U. \+ y
$ S9 B2 Q% O2 q, y+ X8 s
: l1 ?& ^* J; E% i) l6 ~TQC110   
+ w+ r, O( t2 y! y) qimport java.io.*;% c' H6 T. E  L0 V7 Q' k8 Y
import java.util.Date;. ]* x0 R* k- u

  h6 p' U2 @  p2 V; z6 d: W! _    class TQC110{9 p' u: t, j4 x! x2 }1 C
        String items[][];
8 J% ^& f1 N4 Y, N- H  T        long start, end;6 F4 B& i' \; u
        Date d;; U! z' b/ b7 T: R
        BufferedReader br;$ I5 q3 e+ h6 Y# X& o6 z
, M9 d7 W" v- n0 a
        public static void main(String args[]){& G9 ^- e) }& d
            int total = args.length;
; c. e8 w5 T9 _& @            int pairs = total / 2;" ?; r7 p* G" n: p# W! p
            TQC110 tte;5 E2 @* R0 [+ `, {/ f; w' q" Y( E
            if(total != 0 && pairs != 0)* j2 O$ Q! m8 r5 v
            {
% ?8 N: V3 y/ [) j7 ^; ^+ V$ A9 n0 F/ [               //get value from args..
: N. L$ @0 W( q6 ^! u              String[][] tt = new String[pairs][2];
* u" b( \/ q& W2 f4 U' H              for(int i=0; i<pairs; i+=2){/ [' I  S2 m- z
                      tt[i][0] = args[i];) G% W8 F7 l! r' W
                      tt[i][1] = args[i+1];
" K5 U% c$ D3 V$ r) Q, Y$ u              }
- Y5 i2 _5 ?- F  Z( \0 z              tte = new TQC110(tt);9 |8 b: E$ u& Z( J8 y
            }else
% {5 z8 I' @6 a4 Y                  tte = new TQC110();5 G- Y$ a3 Q* t3 y* A5 I) E
            tte.start();. S* a( M5 l( p/ L% Q
        }. P) ~6 |6 C7 V: @0 N% a9 c& F8 @

6 c+ u  ?6 d4 _0 C' k        TQC110(){3 U8 g5 n' J0 q) {& ?9 O& w, g
            items = new String[5][2];1 C, }: V& u! ]7 n
            items[0][0] = "電腦";. c) ?' z% Q3 b% z/ K, ]( z
            items[0][1] = "computer";: p$ O0 R! w/ k* g" H4 _
            items[1][0] = "資料庫";
5 P7 O3 Y% R8 f+ }1 G* z6 D2 x            items[1][1] = "database";. J  t4 w1 c2 l+ e4 r2 V
            items[2][0] = "語法";
4 ?* s8 i) L/ s) w% E5 {1 T            items[2][1] = "syntax";- J, ?9 T( A9 j( f
            items[3][0] = "學校";: B9 W6 w/ B" }* E6 _2 z$ H  Q
            items[3][1] = "school";
. J/ @+ X/ _: F; c7 R" }            items[4][0] = "假期";. k' Y) _( o. E: z* j' t8 ^
            items[4][1] = "vacation";( n, ?8 l; [, E+ c6 O& U" i
            //make default value+ \+ w$ M5 ~/ v4 N4 T/ @- z! j
            br = new BufferedReader(new InputStreamReader(System.in));. ^" S9 |% q4 u! E! L
        }
+ {5 Y% O5 e; v7 ^# i6 Y                   9 k+ Z% [  u/ t1 w" Z9 B
        TQC110(String[][] it){
2 ~( E; j1 c2 H6 M, F8 [; W, A, W            items = it;
8 ]" L# ?1 }: o" H: n            br = new BufferedReader(new InputStreamReader(System.in));
$ C- o9 P& a5 P! G* F& K- s        }8 n/ h1 N6 A0 W0 I6 x( A5 B$ u
                   / P7 q% I1 ~/ V4 v% y
        void start(){
- w, W: a1 h* U" ~7 j$ t& {6 M# C' I            String ans = "";2 G0 `8 d6 q0 \3 w- ^# j
            int correct = 0;      // 計算答對題數
8 ~6 h" u/ b( i            d = new Date();
. ]: Y/ r/ d( J4 Z5 a            start = d.getTime();  // 開始答題時間) A" l" ^, i/ L+ O/ w. _' f+ N
            System.out.println("請將題目的中文詞彙翻譯成英文單字!");& l! d4 {/ A9 G, Y, L0 k+ u0 X
            System.out.println("輸入英文單字答案後請按Enter鍵:");
( V; F$ H: q: L' C            System.out.println("           ");
2 y( t7 H( v+ t0 Q1 U( |            for(int j = 0; j < items.length ; j++)( ]! o9 U/ K9 ^% z1 Y/ N
            {
/ u" a. i- y$ F. l! R                System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
  g) F6 z% G/ D* y9 t2 K+ z                try{" D( F, g3 w# C. Z! I# a  \; _
                    ans = br.readLine();
# w3 l, j% i5 D: l+ D/ G                }
. ~: \2 a* h7 t! c8 W' Q3 ]9 B                catch(IOException ioexception){
" K. `" e; u; z1 g+ N$ \1 n9 `8 r/ S                    System.out.println(ioexception);$ T# x, U9 c9 B& M8 k+ P
                }, j0 K! V: @4 P( J# R8 r4 V
                if(ans.equalsIgnoreCase(items[j][1])){0 B, y7 m: c0 c# |) [
                    correct+=1;
9 @% V. o1 e) U5 J* c' f" V                    System.out.println("答對了!");' K: G+ }) `  _. w3 j
                    //count correct% y8 \+ z5 u5 e! y7 e
                    //ouput correct message
" ]1 o: n% F1 B0 ]& [                }else{! c/ ^3 a8 p' c& @+ [
                                System.out.println("答錯了! 正確答案是:" + items[j][1]);4 f8 m: Q: r2 R3 L+ c, ^% o
                    //ouput incorrect message
7 U4 J0 m9 y8 g                }2 c% T& h1 T/ F8 e4 j4 z
            }8 E6 Y7 L. ^# ^  @9 E* s

1 f- B- b* A+ G3 M4 L! B            d = new Date();
7 B4 q" Z$ ^& b/ c            end = d.getTime();    // 結束答題時間7 B/ |/ d' A4 l, v, l" _4 ?
            System.out.print("你使用了" + (end - start) / 1000L + "秒,  在");- M  o) [. K; M, y  B
            System.out.println(items.length + "題中答對了" + correct + "題");( ?+ b/ D' z* V4 I$ o5 K* E
        }
0 _2 W+ X2 d+ E( h6 K    }

返回列表