返回列表 發帖

TQC107 ~ TQC110 答案

TQC107
. R7 Z, G- v7 @% s6 z( E  @public class test{' P# }8 U0 p, S" J0 z
7 e  }3 p& h; `* H! F8 d. l
        public static void main(String args[]){
4 D9 }- ?4 c, j. f' w# a3 u: A; g        
2 r, k( {4 W# L" L, I$ W. u; s0 ~                //0 1 2 3   z% ?6 d/ E) p8 k- o3 f9 o
                //1 1 2 3! m8 ?1 u8 d4 U
                //2 1 2 3
; U) d+ \/ ~6 {2 x( |1 l                - {/ P* E( I9 @+ F
                float tot = 0 ;+ z/ K+ f" F+ e0 O) L& {
                for(int i=1;i<args.length;i++){
+ [- i( D; ^; \' ], \' x3 m$ G% E                        tot += Float.parseFloat(args[i]);) B7 c) C# r+ Z2 T8 H4 K3 V
                }2 i# J$ L0 T$ z; g
                tot /= (args.length-1) ;
" I3 T# _. V% Q$ w- j. z                : L$ P" O5 [- K, S, t: m" E
                if(args[0].equals("0")){
0 q9 \5 ?5 F# _                        System.out.printf("平均值:%f",tot);$ l( z6 v4 f: g
                }else if(args[0].equals("1")){
, w6 ]! R- l0 ]4 b3 W                        System.out.printf("平均值:%.1f",tot);
" [" ?, S( L0 x; W                }else{# y5 `1 w( d" i+ [5 b2 _. d' {
                        System.out.printf("平均值:%.2f",tot);
2 y: {* Y# j4 h3 A: v9 L1 Q' {                }. C" \" `8 ?, A% Z; }0 u; N! q
               
- o: N: T. X7 r$ z2 [% N# [/ W               
/ ~7 o( v7 P* R7 @, q% {$ B' e        }  t( r6 U' _, l% Q; |7 j5 @1 T

, Q' T4 U$ h( \' C% s" k6 S( Y. o) i2 M8 Q. P2 J$ o" `
}
7 H' o2 P. y3 \' w& c4 Q1 nTQC108
* d$ ?9 X) E8 B6 Q/ R. B! Nimport java.lang.*;! N0 u1 R% a* D& O* l/ I7 s2 Y% t! d
3 b0 e% m  O. p# k! j
public class TQC108
! E" F3 }* u8 k0 C: Q2 l6 N{0 O# e$ q  w8 ]6 I
  public static void main(String[] args)                                         . D% F6 i; Y8 s
  {
  a# _3 v) l9 b, |5 |' x$ R! I   for(int i = 1 ; i< 10 ; i++){
3 ^5 V+ Y8 @; e/ |8 n8 e      for(int j = 1 ; j <10 ; j++). R; W  x6 W$ H! \
         System.out.print(""+i+"*"+j+"="+(i*j)+"\t");- ], Z- ?$ F9 K. b
      System.out.println();
" n2 J5 X+ ]5 C) S7 F( p+ ?   }
% x6 S- Q) [2 M* R+ ?: ^5 K& ^  }9 M0 y  d$ P  K% G% l' ^
}# c' Y6 U8 c* M( q7 `
; X9 j( ]1 b8 Z2 b5 d; s9 ]

* }0 l5 I% j+ W7 O7 d& _7 sTQC109
2 u) t$ L; E3 }' J! W1 J$ e5 jpublic class TQC109 {
/ u7 B$ b+ i. q3 ^. ^  e  public static void main(String args[]) {$ ~/ e8 j% h9 Y4 F7 n  w
    int r;
: ?3 K# ?$ J9 Y" ^   r=(int)(Math.random()*100+1);4 m2 a2 ~8 g+ a8 X+ m" T
   double area = r*r*Math.PI;
2 I: E( z9 c" h3 a+ l+ d$ B7 |3 t   double vol = r*r*r*Math.PI*43;
) L5 t2 ?1 |: {/ |+ ?   System.out.println( "隨機產生的半徑為:" + r );% ?( O2 S3 k/ U8 o3 E4 S2 ]# j
   System.out.println( "計算後,直徑為:" + (2*r) );% ~5 Q- r% O8 U6 w( S9 m
   System.out.println( "計算後,圓面積為:" + area );
* h9 L5 x, E: H/ ]   System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);; H* J+ w; a( j
   System.out.println( "計算後,圓體積為:" + vol );
% l8 u3 f# k$ Z( d4 {# @* B   System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
2 `. H6 b; n# Y  q2 _; H, t+ p# i  }( U- J9 o* ^9 H
}
1 M2 h, ]+ F# P$ \/ C# V! `
3 {4 O# G, H) \7 m6 K
& z5 ^+ \9 A/ A5 MTQC110   
3 I" S: E6 _" K5 P8 e/ ximport java.io.*;. }) \! [( Z. z8 T3 \
import java.util.Date;2 A% e! Z8 W: j

% u. r* Z# g( {- s5 x9 u    class TQC110{! X9 [+ W  T* @' i/ M
        String items[][];
/ e) E2 ~$ B: U! N+ Q/ N0 o        long start, end;+ ^% [/ Z. l$ ?# v; Z  h  r
        Date d;
2 v- O# C4 R) Q1 x        BufferedReader br;$ w) R  p& f' f

' b0 B( H+ W  G  a        public static void main(String args[]){
2 h2 d! h4 S' c  b% U, \& ]( `# j            int total = args.length;
4 m- |9 o' U0 |- T! \) C# G$ n            int pairs = total / 2;0 j8 a5 T- y) M1 _# N
            TQC110 tte;
* m  C. U7 R. m; g: t  }  r# w            if(total != 0 && pairs != 0)
" k2 ^) L; l, @) B( l1 O' t            {
+ x9 v* e6 Y9 B- L' G               //get value from args..3 L, P0 [( s! ^; M6 }" X% f
              String[][] tt = new String[pairs][2];
- W) d2 s8 O# s* ^# S/ y              for(int i=0; i<pairs; i+=2){! l! b# z! G. [; v0 \- n' R
                      tt[i][0] = args[i];
/ t+ P! ?8 \1 Q( N; c- E                      tt[i][1] = args[i+1];
' Y' B1 {* d. D  I4 f              }5 a4 x( K9 X. K1 @
              tte = new TQC110(tt);  H/ O! v6 s3 D+ p& z# Z- ~
            }else
8 S0 B7 y6 L) w4 k, P- i                  tte = new TQC110();( Z$ l4 a& h: f
            tte.start();5 j- a- d- m* q: ^! c! g- e
        }1 p2 k* ?4 G, y# y4 I

  Y4 X- N4 a% i# x9 \        TQC110(){
  q8 \1 i2 u  }: o            items = new String[5][2];
% V1 x6 Z& A- Z& r3 U# K. A            items[0][0] = "電腦";" ^0 ]' r- q0 ^
            items[0][1] = "computer";
& t) T5 p( R$ V& \, T) f            items[1][0] = "資料庫";1 b( y9 l8 X! u) [1 g
            items[1][1] = "database";7 E6 \: j7 G; a# ~
            items[2][0] = "語法";, G" y* m- b( o+ Q/ I) p, x4 A8 j+ _) I
            items[2][1] = "syntax";
; q1 g* i1 h. Z5 Z0 M            items[3][0] = "學校";0 R4 v: R& Q! {4 g  G8 x
            items[3][1] = "school";( w6 r" D4 q9 H! ^# s
            items[4][0] = "假期";& K  f$ G/ G% k" S- r( T9 k
            items[4][1] = "vacation";
: h$ }! P+ ]6 j0 J8 U' b; y            //make default value
# h8 S! u9 u. n" h            br = new BufferedReader(new InputStreamReader(System.in));1 R0 X- `# ]1 F+ ^+ [  T3 n. g4 e
        }2 K5 L7 Z8 U2 p
                   ' H5 a+ r2 A% b: r+ c7 p) N2 W& ?
        TQC110(String[][] it){
* Q; T9 ~1 X2 l2 \$ f            items = it;" w6 Y) u. b. Y2 f- g' N
            br = new BufferedReader(new InputStreamReader(System.in));
3 \& e9 s' s; X* P1 F+ B: H1 ~3 I  [8 k        }' A5 W" R# n3 N" l# E, b2 h
                   " o7 q3 h. S) x2 i( T, L) o
        void start(){4 D) @1 K# \% y, V! e3 E2 g  Q
            String ans = "";
5 B1 l5 _# B& J6 q1 b. J+ v            int correct = 0;      // 計算答對題數4 U  A) X& b$ p3 m( w
            d = new Date();4 s0 Z: O+ @) \! b
            start = d.getTime();  // 開始答題時間
, e" q4 J2 h) A" E6 c: Y            System.out.println("請將題目的中文詞彙翻譯成英文單字!");. }% c2 c6 B% K# E3 M" y
            System.out.println("輸入英文單字答案後請按Enter鍵:");" A( W+ g8 e( l8 i) l8 }- i
            System.out.println("           ");
+ I4 S" ]; ~: m$ ^            for(int j = 0; j < items.length ; j++)/ ?0 ^/ n: R, F& n8 h9 U
            {
; y/ _: C8 G3 k8 `! _                System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
. X' p- w) w! K! y! c" s) h- K                try{
2 a0 `, S8 L# J; q2 B                    ans = br.readLine();
  {( Q. x1 t) d+ M, c. g; D                }
2 l2 o0 }  w/ @/ h! ^                catch(IOException ioexception){
% Z3 C: z+ A8 q/ p- I                    System.out.println(ioexception);
  \! C! f! D/ Z                }
0 v, w; x8 M: z. j; |& |% \! G                if(ans.equalsIgnoreCase(items[j][1])){! D: O0 u6 L% S: r' J) A8 U- S
                    correct+=1;3 a- j! M3 r0 C. Z
                    System.out.println("答對了!");
3 P6 j; ?+ w, H. ~9 Q( t                    //count correct  X5 q" j6 q3 T0 I
                    //ouput correct message
: f0 h& w+ G, \                }else{
" @/ F6 y3 A* u2 G+ a% Q' }                                System.out.println("答錯了! 正確答案是:" + items[j][1]);; \* C* ~: d; y  B3 g" j
                    //ouput incorrect message
+ F. J3 ^$ ~! V                }
+ R6 l5 Z9 t9 W            }
  R6 H8 S+ X( _# r5 P- l( l* _- O* Q+ `7 [  ^1 b2 I7 P
            d = new Date();* g4 ^! ~  A# i8 _  i0 Y& @/ m
            end = d.getTime();    // 結束答題時間: G  G# S# X3 t, c  [0 ~
            System.out.print("你使用了" + (end - start) / 1000L + "秒,  在");
: a3 J% [$ s9 ~) f- M            System.out.println(items.length + "題中答對了" + correct + "題");
0 r. W+ ?8 p6 R& D; a: x6 h        }( L! E0 x' c6 o* p% c
    }

返回列表