返回列表 發帖

TQC107 ~ TQC110 答案

TQC107
' w* d) z9 Q/ e. l" M4 [$ e% rpublic class test{
: H  _8 ~6 y# \7 i* J
* f! x/ `/ N# g8 g        public static void main(String args[]){
) V% z" ~. S  V' M* ~$ X$ M. i* b; u        
8 x/ p; I7 m6 |# k& X                //0 1 2 3 6 ~* g4 @, @4 S( o& W$ t8 c
                //1 1 2 3
( G6 [( y  X$ v. R& W% |  J                //2 1 2 3
  ~% x$ T* B8 t                  x0 r! p4 @- O  ]6 n+ ]9 a/ i7 x3 x
                float tot = 0 ;
$ M9 N$ ]9 }6 B5 C                for(int i=1;i<args.length;i++){3 @! r* y: e4 B! W
                        tot += Float.parseFloat(args[i]);* s! J, p4 s: W( `% y- I* \( ?* W
                }+ B4 G0 h' O( {  w, @0 G. [
                tot /= (args.length-1) ;( X' X- z6 G& A: }6 T: f9 e# ]
               
% q$ M0 Y- s' K% }2 n+ h                if(args[0].equals("0")){/ n$ j5 j  x+ x! n
                        System.out.printf("平均值:%f",tot);7 S9 b. h! h/ C$ s. R
                }else if(args[0].equals("1")){
# l) t; O# ]; k" t$ n/ `/ d, ^                        System.out.printf("平均值:%.1f",tot);( F2 h0 V) s4 I+ C
                }else{$ e7 [7 C* @: y7 y
                        System.out.printf("平均值:%.2f",tot);8 v+ g* |# i; P# i
                }( @9 R- V; C) _. [; @6 ], V. [
               
; }# [, _$ }+ N4 J               
5 W9 O- ]. @) U/ z" U        }* N% z1 o% ]% d/ p/ n+ M) {

& {9 \; r7 ?. w% h+ {
. t% n5 y  v6 e( D2 ~}
8 x4 T& @/ k- ^  o+ _& B. pTQC108( _, g# ^9 G! E* `% V
import java.lang.*;
' z. _1 `% ~8 x4 _3 R3 |3 v0 \2 W: b& B( r$ d
public class TQC108" c/ \7 _6 g) A1 e
{; b, C- K, V( A
  public static void main(String[] args)                                         : s* k  Z. I+ ^
  {# y" V! G9 v' G, T
   for(int i = 1 ; i< 10 ; i++){
# h9 D" c6 r; t3 K% T      for(int j = 1 ; j <10 ; j++)# a* E, c. r- D- r  ^
         System.out.print(""+i+"*"+j+"="+(i*j)+"\t");9 z4 i) ^2 S# ?
      System.out.println();. O6 @% v! s0 e( ]4 l- Z( ]6 U6 O
   }! A# g8 [) e( M; {" B2 N. S
  }
& ?* [. z* H" C7 w7 _) q7 f8 b}/ e& y- F1 T; D' G9 N1 [
4 K0 f$ o; h+ \0 j2 C
% C! w* S  C. O* k# ]
TQC109+ `. B! C* b0 \3 }, A4 u4 O) w
public class TQC109 {
7 J( {: Y, w& g: u  public static void main(String args[]) {
5 v# K1 W3 Q, E0 A    int r;4 i, W- `% A5 v0 w3 j* y
   r=(int)(Math.random()*100+1);
: a- a* Y0 C9 Y* W4 e+ r# q# u   double area = r*r*Math.PI;9 f; f( w2 C% Y6 f0 b. [
   double vol = r*r*r*Math.PI*43;
! }( w( u2 P0 M4 z5 W9 \   System.out.println( "隨機產生的半徑為:" + r );# B$ R9 E8 Z! D& X9 S2 [3 N
   System.out.println( "計算後,直徑為:" + (2*r) );
! W+ U  W5 e5 b5 d8 E   System.out.println( "計算後,圓面積為:" + area );- S3 u+ V  G1 J9 I9 x3 f' V
   System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
+ O9 h8 V3 D2 x: r, r9 o" l   System.out.println( "計算後,圓體積為:" + vol );* ^' _+ Q% Z, z& _5 ^
   System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
6 b$ C$ ~" J' q! a0 q& {  }# h! u& ~  g* V- ~
}/ [# d/ r. i7 r: {. F+ l. K/ D
  V. Z5 v) [' F
, s8 M4 B2 }0 A2 ?8 n) m2 F
TQC110   0 \: a* k; _3 ^, ?- B, |& N! |
import java.io.*;
% H" v' o9 D8 Simport java.util.Date;
) V% V: F/ l, W2 M( j0 }5 Q4 C4 N2 a- z7 N4 E( O0 X2 a
    class TQC110{2 j' j# J, c' f: w
        String items[][];7 w1 n2 ?1 j5 l6 p/ H
        long start, end;9 l, V9 Z" _4 j/ E
        Date d;0 l* `# O, S2 k9 ~0 p
        BufferedReader br;9 h$ {9 x! c( @- T/ |6 }
( Y; {" U% L4 n3 L" ?
        public static void main(String args[]){7 `% @* n: k. j- Z8 F9 s- w! ]
            int total = args.length;4 A7 a, w! S; v8 \  ~5 J
            int pairs = total / 2;
( ]7 q1 ?& b1 t2 a% ^7 g  q3 `- t            TQC110 tte;) @$ t# u% o8 N. P+ `. d, _
            if(total != 0 && pairs != 0)$ [: c& U# ~. ?+ E; ]: t' c# c
            {  c& |# c  y$ w" Q$ j: D$ \: S7 o
               //get value from args..- x& @7 R9 @" \; _
              String[][] tt = new String[pairs][2];
6 h; F% `% T. x9 z              for(int i=0; i<pairs; i+=2){( \) u" |0 r9 M, |9 [1 s3 O) B
                      tt[i][0] = args[i];
" Y3 g, e4 p! O( m! N! h/ o+ V3 h4 S/ Z                      tt[i][1] = args[i+1];
3 B; t, f8 l* I& V/ v3 O              }
- [) F3 |. X% F! e6 p- {/ J% l              tte = new TQC110(tt);" s( j6 _& k9 B3 L! i6 y
            }else
# f/ M: {# \. K$ R. t4 ~* N                  tte = new TQC110();  b7 Z8 G5 a, ?4 x$ V% y# R
            tte.start();& C+ S4 I5 ?- @: f2 a! f
        }
! [5 A) p- Y+ K3 q$ Q- ~
; X5 W! k- `5 G3 e        TQC110(){
. f7 f9 k7 E- @# L6 l            items = new String[5][2];" v2 I% x  T' f2 r$ i; e
            items[0][0] = "電腦";
% S8 e! i+ b2 k& ~& ^& B2 r            items[0][1] = "computer";2 E/ R+ e* E* r, d* I( E/ o
            items[1][0] = "資料庫";6 m+ w2 V- q2 a( o3 X
            items[1][1] = "database";
! _1 J/ c% W( Y( t  m. q0 N9 S! a            items[2][0] = "語法";- \' E; G: q  @7 n3 ]: _% d# t% q
            items[2][1] = "syntax";
$ D1 N! L2 `9 k# W3 _$ F6 a            items[3][0] = "學校";
  h; G1 s, C7 @# S9 l# o* V% t5 y7 f            items[3][1] = "school";
9 h: Z5 B, R7 [/ H. i. N. y4 [            items[4][0] = "假期";5 o$ N# O& }5 w0 t" d+ ~
            items[4][1] = "vacation";
8 c* Z* m+ S( b, o! L7 q            //make default value, Q# y0 z& E1 Y
            br = new BufferedReader(new InputStreamReader(System.in));5 Q" g7 y: `8 Z  J% r- k0 i
        }- V+ }7 Q9 h& S' r" V8 _" W
                   7 l5 x& y0 [1 ~, ^, T" a
        TQC110(String[][] it){+ g; ^! _* B& X' I9 O
            items = it;
/ x+ C& b5 Z' b/ {            br = new BufferedReader(new InputStreamReader(System.in));
* T; R) R' h$ y* `        }% F; }% U! u: g
                   " [: A5 q6 C- A, s1 m* r: u  {
        void start(){
0 ]1 d, Z; D  f9 ?$ [8 Y            String ans = "";1 }! A# Q# ?2 T" q: j! S
            int correct = 0;      // 計算答對題數1 ~, j2 M5 l9 \9 }/ A$ h: v& [
            d = new Date();$ a. x& u* E9 |- D! a8 K/ Q3 B2 n
            start = d.getTime();  // 開始答題時間3 m" @2 @( u& C% G7 ^) j  K
            System.out.println("請將題目的中文詞彙翻譯成英文單字!");4 Z1 n$ w4 r' m& W: p1 H
            System.out.println("輸入英文單字答案後請按Enter鍵:");8 @3 A; b$ _0 [( V* i; q) ~& i, S
            System.out.println("           ");7 J4 W/ g* q" F# [; X. K8 P8 E! P' Q
            for(int j = 0; j < items.length ; j++)
+ S9 x: l5 q6 p2 o            {7 R7 d, |! E9 @$ F  H8 o5 Q+ }$ I
                System.out.println("第" + (j + 1) + "題__ " + items[j][0]);  Z. p% c- k) Z
                try{
( j! y' a0 N: `; v                    ans = br.readLine();% W( V& s% p; q' A
                }( h$ w/ K1 q- r8 S) [2 k  T# b
                catch(IOException ioexception){
  o9 V6 ]5 w9 R# q* f% ]* ?4 L                    System.out.println(ioexception);
$ t5 A' A) _+ s( P7 }                }) m5 M9 b3 n! u" N" N( v
                if(ans.equalsIgnoreCase(items[j][1])){
7 X4 s  C" M: x1 u                    correct+=1;
* x" {( E8 G, f2 N7 `                    System.out.println("答對了!");1 I- k& E7 h0 z1 \( h% h# F; p
                    //count correct2 W1 J- v7 k: e6 H% g; |
                    //ouput correct message
  Z2 E1 Q- J% W# u- ?" {3 Q  |                }else{0 V. ~  O' F7 U) K
                                System.out.println("答錯了! 正確答案是:" + items[j][1]);
) C+ I2 I% B0 I3 V4 R" p                    //ouput incorrect message
5 a5 O$ e4 ?, P$ H& L8 K. s1 T                }
' N- P- ?; C$ o            }
0 T( _# H) l+ {
% ^& i" v' o2 T2 |            d = new Date();5 p7 A9 ~+ c3 V
            end = d.getTime();    // 結束答題時間+ ]- n: d& _8 z2 Y  o( g. S
            System.out.print("你使用了" + (end - start) / 1000L + "秒,  在");
4 f: ~) s8 Z* s! U( Y            System.out.println(items.length + "題中答對了" + correct + "題");
5 q1 {5 M- g8 O- P2 }, c0 R        }
+ N/ q% q8 B/ s6 v, ?  c* `% t) Z" w; Z    }

返回列表