返回列表 發帖

TQC107 ~ TQC110 答案

TQC107
# f4 E% I9 T( \" H' p& {  }public class test{8 g0 W# F* T/ G$ X

. b0 }: b  @! |6 L3 ~9 O        public static void main(String args[]){
2 P, l2 t9 j& A4 ?: n5 w; i2 {        
* w- n+ f( j9 I* w& d) F# f( C                //0 1 2 3
! o5 |% `6 o  [3 q                //1 1 2 3
# d- h; g: h. r/ B' U, G) E8 W                //2 1 2 34 D4 L8 m% A6 K# o- B$ Y( C4 T3 q0 x7 h
               
& ?8 ^) `) n/ X! ?3 O; `                float tot = 0 ;' E% ^4 X! m# c2 N) }, C/ N
                for(int i=1;i<args.length;i++){4 |. s7 U( v0 [! a" V( Y
                        tot += Float.parseFloat(args[i]);
" i/ n* D9 _  |7 k8 v                }7 Y- A* ?# W2 V0 N% K
                tot /= (args.length-1) ;, U# |( P$ ^' m* Z8 w/ b- C
               
, B0 q3 x5 `9 W6 [  i                if(args[0].equals("0")){, k# S5 Y% ?! D& N( ~
                        System.out.printf("平均值:%f",tot);* {$ i. b* |$ s
                }else if(args[0].equals("1")){5 Y7 ]  D; ~" j. i
                        System.out.printf("平均值:%.1f",tot);& D& o; Q' n  `  i. S" @! l# q
                }else{$ M6 v  K  H7 ]- i4 w5 r
                        System.out.printf("平均值:%.2f",tot);$ U  c/ O5 @% y0 \+ @8 ^) i  p  x
                }
' a) H* A' C0 D               
5 o1 V, G7 k) d( D2 t# l               
0 ]/ H9 h! q# y        }2 C- E5 l0 q) X  y& P' K

0 c, E. P3 ^& ^2 p
: P5 @- L* N  O' ^}
, Q% L! ~3 a5 y: N  _TQC108
/ a% [. q' \/ J  _. }import java.lang.*;
7 ~5 M* ?2 V  j$ d& c# l; R6 I5 j: X% T9 ]  s
public class TQC108
9 @3 |1 n4 y5 t6 g' ]7 R{
7 v. M& I9 s: w( t: i& s$ s  public static void main(String[] args)                                         & e; O8 V6 R% W8 U1 r
  {9 A8 y, U( z& P" K# W  Y& s5 P4 x
   for(int i = 1 ; i< 10 ; i++){' K( z% o6 O$ E& [& X  A! D0 w
      for(int j = 1 ; j <10 ; j++)/ o- P3 W7 P  e1 L6 a, N
         System.out.print(""+i+"*"+j+"="+(i*j)+"\t");7 T; d) [4 I3 b* p7 W) H/ X0 @
      System.out.println();8 P9 O% L: M/ N) F4 E1 z: P
   }/ K& M; ^2 R2 ^+ a. b
  }! `9 K7 y9 J1 z5 Z0 t" D
}9 n" z/ v- ?. s* X* Z

. P/ x* D/ F- g' a5 z" |# D) G' V& D& w0 N6 c. f( w! J  ]
TQC109
. Z* o# ^* z4 g8 O+ ~public class TQC109 {
- I' A4 `- E" z- r* _/ p* _  public static void main(String args[]) {
/ H# G5 |% X1 j( r# z3 Q    int r;. h8 l: H/ t  O! T
   r=(int)(Math.random()*100+1);6 ^+ h5 t% H! J. @! t8 Z1 s
   double area = r*r*Math.PI;
6 R5 W+ s& j' N   double vol = r*r*r*Math.PI*43;0 T+ X! y" m! y9 S  D2 P% G
   System.out.println( "隨機產生的半徑為:" + r );1 S9 }4 E+ p$ G* m) x
   System.out.println( "計算後,直徑為:" + (2*r) );1 T) K  J9 C' f4 ^
   System.out.println( "計算後,圓面積為:" + area );, i1 R6 d# D4 G( _+ l9 J
   System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
9 }. Z& N$ R0 ?1 P- V   System.out.println( "計算後,圓體積為:" + vol );- a2 o1 S$ A. n2 X& |
   System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);% K9 J! K! X/ v5 y" x
  }) }) c0 Z+ E0 R4 ^' |
}+ j! @  k  Q9 p9 l  r7 V5 q1 ^: k

9 w/ a+ Y( x& h6 X. n- o! \
3 ?5 p( X% d4 D$ jTQC110   
6 ]  S4 }* p: {5 Limport java.io.*;6 h! S* s% i( n
import java.util.Date;
+ b6 L  M6 _$ O
. l0 x+ z% |6 t+ o1 j( [: V    class TQC110{
3 E5 \' \3 @& J        String items[][];" j- Q. m6 `1 y. Z2 w
        long start, end;
6 k2 G- S+ b8 v+ E, O0 k# E& v        Date d;+ V* j+ O; `6 I
        BufferedReader br;% G4 _, G% m, y; n3 x
# S% j* e: u3 |; J6 H( _" R# {9 z
        public static void main(String args[]){* _# \9 V0 \. A8 P
            int total = args.length;% _# l! B; K/ T- q
            int pairs = total / 2;
3 K: K6 b3 g1 I            TQC110 tte;1 m1 B9 A* K- q% E4 U
            if(total != 0 && pairs != 0). e1 M& \4 F  m9 k
            {4 L" f2 T4 O6 o  b+ @0 v
               //get value from args.., B  ?" K0 J- S) f* y
              String[][] tt = new String[pairs][2];
$ [# O6 `! ]: i7 e# U              for(int i=0; i<pairs; i+=2){
6 ~4 ?- d+ J1 y                      tt[i][0] = args[i];
4 j; \5 k/ h3 i0 a                      tt[i][1] = args[i+1];$ q/ w# q" d/ B) t: Q" c
              }  n  L- Y# o! ]" t
              tte = new TQC110(tt);
" d& U' J5 W, o; m9 ^            }else
8 k8 {8 k! e' A                  tte = new TQC110();
, d9 U# R5 [: L- d. x            tte.start();
0 F% d3 j. b2 ]7 Y0 p; V& @1 }        }
: C& N& r2 [+ `8 @. w' z) H; b# t1 U3 T9 h. B5 D* l
        TQC110(){) F. U; {& t3 K$ H  k2 {
            items = new String[5][2];; n: ~+ r5 Q9 Y$ z& ~3 }
            items[0][0] = "電腦";
9 F& {. @3 U9 }5 ]            items[0][1] = "computer";- B; I6 @0 G+ c9 y! ~, }/ ^
            items[1][0] = "資料庫";
3 \/ @- ^4 F) T: N6 F9 V4 v7 G            items[1][1] = "database";) n% I6 t: T& t! Q1 @; M
            items[2][0] = "語法";( d8 K/ R2 t4 y+ @
            items[2][1] = "syntax";7 h# W; t0 e" Y9 K
            items[3][0] = "學校";
8 i8 f+ J1 `$ t+ I" r            items[3][1] = "school";
' u+ y1 T# |  B- T            items[4][0] = "假期";
; g3 v* _7 k2 Z+ @! ?5 i; p& L. v            items[4][1] = "vacation";
' P) c% [: j' `& a) ^. s! U3 C  T- @            //make default value
. m& g$ S& r# }' l+ ]            br = new BufferedReader(new InputStreamReader(System.in));
* q5 m: K0 E& T  J        }
5 Z# M2 @- O: X) P! Z* f/ z                  
2 Q  [: h: c7 E        TQC110(String[][] it){
' M$ ^6 t! Y  a/ i. z            items = it;+ _# \* `0 N7 Y) q# k' W! p8 A
            br = new BufferedReader(new InputStreamReader(System.in));8 E* B: r, E9 `' k) b0 ]# O
        }4 n4 f% z2 V  Z3 B9 H
                   + ?" i' X) h2 V/ P
        void start(){% q6 }3 l; b: ]( h% k& c! H
            String ans = "";5 \# C( D6 f) t1 t! r5 }1 M- P# @
            int correct = 0;      // 計算答對題數4 ^, w. ]& F4 P: x" e5 b# m
            d = new Date();
" t4 U  _( z; u; k2 a" i4 w            start = d.getTime();  // 開始答題時間
) k% }+ }0 h1 J4 Q) X            System.out.println("請將題目的中文詞彙翻譯成英文單字!");
9 j6 P: O& K  x5 p+ Y# w- k            System.out.println("輸入英文單字答案後請按Enter鍵:");
) E: k/ i+ T  c5 n  h            System.out.println("           ");
& Q. ~) d" u6 p7 y+ F6 N            for(int j = 0; j < items.length ; j++)
: x3 x4 T9 c- j5 c& C            {8 p0 U$ X6 g" G9 [; M. c' x
                System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
# n- ^+ O2 u. W1 R, D                try{
1 K+ p, Q' {. p( p' ?# T                    ans = br.readLine();
% j- a% }6 b2 n* N( ?- k. o: Y1 ~                }/ t; L* V" F& K# F+ K% B
                catch(IOException ioexception){
+ R* t% M% I) R                    System.out.println(ioexception);
# H" N4 R% Q1 ?" _* z* W% m                }
& n! n& `+ G8 y% W. j                if(ans.equalsIgnoreCase(items[j][1])){
+ I; i* C% H* k. x1 @                    correct+=1;
( G2 @5 u! m$ h4 m( K: r: a                    System.out.println("答對了!");
9 W1 M2 g2 {! ?                    //count correct5 d& T0 S: V7 t8 G. ?. D
                    //ouput correct message( S: i9 C- V6 [- F1 `
                }else{
, y' p1 Q0 d! }$ c8 C3 ~                                System.out.println("答錯了! 正確答案是:" + items[j][1]);
/ q! o# \4 P+ R# L6 i! `" @% a4 C                    //ouput incorrect message
( I4 I- F" N& D& k. o; G                }$ q8 S# ?7 t  \! ]% H5 ~
            }
( o* @/ F0 N" Y- Y7 v' p. e- @, g  L5 ~- h0 ?4 Y
            d = new Date();
# E2 H( Q( `$ [            end = d.getTime();    // 結束答題時間( R) ]$ q  q$ s
            System.out.print("你使用了" + (end - start) / 1000L + "秒,  在");' h* Y# U4 p) n( t8 N) o
            System.out.println(items.length + "題中答對了" + correct + "題");) w- Z2 e/ w  s4 V0 B
        }1 a$ w8 `/ V; R( w
    }

返回列表