返回列表 發帖

TQC107 ~ TQC110 答案

TQC107
2 s. e6 e0 p4 B6 b, g7 `public class test{
* T1 m; ~( [- ~0 w  T
# g& l6 T' g! \; J4 W, s        public static void main(String args[]){% X+ N; \/ b6 `$ g! B. K
        
2 u; e  j& T# p6 G7 j  s                //0 1 2 3 0 o' H; K. v: r  ~! }! c
                //1 1 2 3
: ^9 g7 \; u- Y- Y' ~5 {                //2 1 2 3
7 F8 y* ~6 T# F, N6 j5 c               
9 z1 l7 `: J; s" v0 J                float tot = 0 ;
  {* X2 {! k7 a                for(int i=1;i<args.length;i++){
. r4 {6 k; O, \8 e7 I5 u2 Z- V                        tot += Float.parseFloat(args[i]);+ T. f9 R6 @5 b0 x5 ^* m3 }
                }& v2 |6 z. l7 N8 J
                tot /= (args.length-1) ;5 X6 E; T& g0 [3 l5 h
               
' |( S) V+ O' x                if(args[0].equals("0")){
" H, ?- h9 }! ~9 N" m                        System.out.printf("平均值:%f",tot);/ f- v( j- ~6 A3 }7 u' M
                }else if(args[0].equals("1")){
9 ?5 p7 {* W/ Z. a                        System.out.printf("平均值:%.1f",tot);" k  p6 n/ Q: n5 K
                }else{' F; Y& [4 N& m
                        System.out.printf("平均值:%.2f",tot);
( |3 X8 _9 ~  A1 i                }
. w5 }9 ]5 d+ e% ?5 Q8 ^2 M6 A                9 y/ r/ L; o8 d
               
6 o+ n# e- A2 a4 A2 ^- F% e& t        }
6 Z0 M" {& T! U' _* k2 }! h
) N& }; S9 z& X! F3 {9 u0 ?- p" T
1 y5 B* ^7 H0 g7 h}
* @' E/ ^# ~! ~, c; sTQC108
( ^9 Q# s1 D" F7 u8 ~0 A6 W  yimport java.lang.*;
+ t) U5 V9 M. h/ r4 A  s% o8 W5 l8 O1 M4 Q4 [
public class TQC108
4 ~! A) X9 e/ @# a. M4 x0 c: \{
: z! J) o" j, X4 a- w9 P5 Y7 }3 a  public static void main(String[] args)                                         
( H7 F$ Z( @& Z% Z' b  {4 v% w% W) d* Z4 C7 U
   for(int i = 1 ; i< 10 ; i++){
4 @3 E& Q2 s; [1 V      for(int j = 1 ; j <10 ; j++), ]/ C/ r# Y5 B/ X$ h
         System.out.print(""+i+"*"+j+"="+(i*j)+"\t");1 T! x: v- J' j( }) B
      System.out.println();
5 d( X) z' b* K' D& l   }
9 C9 P+ n9 o- B" ~+ `* Q' ]2 q  }, p" E  J; y' `" R$ y0 R! r
}
7 z* l, k) y  \0 }7 d$ b7 w; u% f  v6 {. t9 [

# ^3 M8 ~7 P5 b7 x+ f5 _TQC109
1 a: Y, R! m/ g) r4 K- |5 F1 L6 Upublic class TQC109 {1 E0 }3 u" `9 [/ m3 h
  public static void main(String args[]) {
3 @( U$ i( W/ b+ X3 ~" b" H9 G    int r;
/ t4 ~5 n' P3 g6 E) ^/ X5 [   r=(int)(Math.random()*100+1);+ D5 |* X2 A' A5 o5 h* n
   double area = r*r*Math.PI;
* W- q- C7 D. ?   double vol = r*r*r*Math.PI*43;0 {; v: g4 f) j
   System.out.println( "隨機產生的半徑為:" + r );
/ k  r0 V" L3 i. c0 Y, T) }+ t: Z+ x   System.out.println( "計算後,直徑為:" + (2*r) );
/ m' @6 _/ f' f! R* E6 P2 J* g   System.out.println( "計算後,圓面積為:" + area );
, H& D* O9 e. C/ |   System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);& a5 S' F1 i( M0 W' i* J: i
   System.out.println( "計算後,圓體積為:" + vol );
$ d" {% S6 Z; N, a. {   System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
* E  Q3 R2 Y1 c9 C, P/ u9 _9 q) c  }
" n- I: L" ?9 n/ u$ Y+ J6 ^}
: }$ N- S4 p4 X
7 S# U: ~3 N9 N  b  | ! C: o; G7 a0 X; J4 e
TQC110   ' U( K. ^3 `/ P: Z# N6 c2 ?
import java.io.*;
  y* m; Z1 N) Cimport java.util.Date;
: a2 z0 m% H) ~1 }; t+ m/ C1 ?+ ~
/ s/ x$ U( I& q# B' Q5 T4 }    class TQC110{% \5 Y( p8 j: Z/ X. _: V4 g3 N
        String items[][];
' P: N8 V  Y4 X- J7 ~1 z5 `: A        long start, end;& p: i" j3 q- e5 u2 w* S
        Date d;1 x  }# C) l; I  i  m
        BufferedReader br;
. x  j( j& D) [9 T- x: t+ m# j; ~5 V0 b6 N. s. S
        public static void main(String args[]){& V5 x/ O+ y' m. x# @2 `% Q' U' W
            int total = args.length;# Q1 X+ u: `; B3 I
            int pairs = total / 2;
2 M- z( r' _- f  {: S8 W" U( [" k4 Z            TQC110 tte;4 Y. \; Y$ q0 C6 j9 x6 y$ _
            if(total != 0 && pairs != 0); w( d/ C4 q6 B$ O- j* L! H
            {' T) v% |" m5 s+ N( N3 F
               //get value from args..
- ~( v5 W3 ]; r# ~9 Y              String[][] tt = new String[pairs][2];- `7 t& x  r# L
              for(int i=0; i<pairs; i+=2){
, U% V; }- ]+ v                      tt[i][0] = args[i];
1 `7 u# t" @5 L                      tt[i][1] = args[i+1];  s  ~/ N9 V- P' H8 s- `7 c# o
              }' L; g2 R6 A! v! Q
              tte = new TQC110(tt);
8 z* m  Y1 \9 m4 r0 t6 K) y            }else. V2 B$ {' H9 d2 U' B
                  tte = new TQC110();
2 `5 y- T2 y+ u& c1 a% m. {            tte.start();( a5 P9 G9 b; r3 {: F& h
        }
, ~9 ^; I2 W1 h9 c  t# H- I% B' i) I2 U! T9 |5 \/ t
        TQC110(){
9 u( \, y6 O. ]* n* Q            items = new String[5][2];0 T; R0 s) B; |0 D
            items[0][0] = "電腦";
. q, R7 ]# o+ t, Q6 A6 s) c            items[0][1] = "computer";
3 D' A; V5 m- }  b            items[1][0] = "資料庫";
( f4 h* Q5 ?2 u7 {6 X            items[1][1] = "database";
  Q# |9 c7 M! U1 [' V            items[2][0] = "語法";
9 z( @( `3 L  `  Z9 T( y5 ?. x4 l            items[2][1] = "syntax";
$ Q& b6 p# C) U$ p' ~            items[3][0] = "學校";; |$ K- j8 _3 t, W6 G) b
            items[3][1] = "school";$ p& y' a7 O7 }4 S" \
            items[4][0] = "假期";; V) `' M) W% M8 w; a4 I. i
            items[4][1] = "vacation";  d" u5 d# T2 _. u2 [
            //make default value
/ x" d, z, x* ?+ T9 M            br = new BufferedReader(new InputStreamReader(System.in));4 i# m5 d% C* t# h, ?; n! n2 ?
        }
1 w! |3 Y7 C4 @% S" U3 ]* |                   6 \6 d4 o9 _2 R. m
        TQC110(String[][] it){
9 p5 V  ]) r7 j+ o6 E- ^- }            items = it;
' f! `" p1 i) `/ F            br = new BufferedReader(new InputStreamReader(System.in));
/ w, [4 g) m: b9 o9 Y        }$ ^  Z1 i! Y/ |7 e; T
                   6 n% Y, q6 r7 `% j: F# @. a
        void start(){
, R0 A1 w. _6 j  C. _, m7 g            String ans = "";* R; @. t5 O$ p" Q5 j- Y
            int correct = 0;      // 計算答對題數1 G4 A3 c( h- ^# K
            d = new Date();
7 I& _( C0 Q2 v5 g5 N# @            start = d.getTime();  // 開始答題時間
! Y& v; D; R% J: `, _  P            System.out.println("請將題目的中文詞彙翻譯成英文單字!");
* P- G& z/ |% e% c3 k, p; l            System.out.println("輸入英文單字答案後請按Enter鍵:");
! }1 j/ c- H* P, l  |; N) i, i            System.out.println("           ");
; m+ G3 u4 U, }$ }9 X            for(int j = 0; j < items.length ; j++)
% N1 u9 i7 W. J; G            {
. z4 y1 \( f, q- X5 u- t/ _! C0 ?                System.out.println("第" + (j + 1) + "題__ " + items[j][0]);4 ^& H% H4 r8 N
                try{3 d  r7 a  k  K7 A: |# G) \
                    ans = br.readLine();
4 O* w4 R8 ?! x* y" h( s; O                }
* w% X# e9 A) f2 b! ~( D( p                catch(IOException ioexception){% }7 Z, W$ @( K5 a2 W7 w5 p6 L
                    System.out.println(ioexception);
2 S2 |9 s' l: \; I$ _                }8 s1 s0 x3 U& y  p3 ^+ x9 w8 D* |
                if(ans.equalsIgnoreCase(items[j][1])){" `, x2 w; G0 z
                    correct+=1;  e! j9 K/ C4 z  w3 D
                    System.out.println("答對了!");
" E1 b0 j: D. O. m& V                    //count correct
1 G8 ^" \2 ]) h& p                    //ouput correct message
% ?: u- W9 j# i# w6 W: P                }else{
0 v8 b# u- p$ J3 k                                System.out.println("答錯了! 正確答案是:" + items[j][1]);
7 c  R5 n. L' z8 Q* t$ U                    //ouput incorrect message: Y3 @( m6 d+ S' ?
                }
' G: C! `- h$ U) `9 }8 b, }            }
9 i; j2 A8 T4 a0 ~" n. ^6 F; |3 d% f2 S5 u
            d = new Date();0 A5 s. z" n3 N3 z/ j8 H$ C
            end = d.getTime();    // 結束答題時間
4 Z# B: Z3 j3 g" ?2 ^            System.out.print("你使用了" + (end - start) / 1000L + "秒,  在");
+ h1 d1 S5 c3 s  v. B5 x" ^+ k3 }            System.out.println(items.length + "題中答對了" + correct + "題");
2 g% C% V. F9 Y& i1 x        }
7 p- [% D6 s7 Z9 B. H( t) t$ f    }

返回列表