返回列表 發帖

TQC107 ~ TQC110 答案

TQC107
# ]! `8 c5 ]7 d  T( W& @: npublic class test{
5 O9 [7 A" _# V  |; j9 l+ D( ~5 S! v# G: ?
        public static void main(String args[]){
. v  Y$ D- B7 |* Z6 \$ L& r" T" ]        8 h  m" i4 {( K& c. L4 r
                //0 1 2 3
' z; ~) P( [5 Q# s( o. u                //1 1 2 3
! j4 c- I6 m+ u9 i! g" r                //2 1 2 3- i, m7 ?2 c4 b  D$ u, g8 ^4 d6 S2 ]2 E
                6 a. ^: q. F- S
                float tot = 0 ;
) j) Z1 ^) S$ z& g+ Q9 q                for(int i=1;i<args.length;i++){
7 e# `% \4 y* Y7 K                        tot += Float.parseFloat(args[i]);' h& W2 e! M% }5 u) O8 }% [7 h8 A
                }( x8 M3 z( H- i
                tot /= (args.length-1) ;, l9 `) ~' P1 t: \$ K* R  N( f8 R
                " I) c# N, s% B+ }5 a3 v- Y" D
                if(args[0].equals("0")){5 W8 M: f, t) \* V4 ^
                        System.out.printf("平均值:%f",tot);. X3 h+ @. {! M" ~4 E$ @
                }else if(args[0].equals("1")){3 G/ E  M  n$ A3 W. B1 D; I
                        System.out.printf("平均值:%.1f",tot);
  \9 J( g0 \5 E% s) M                }else{' p4 [5 m: [$ x. U7 J' n+ f0 X
                        System.out.printf("平均值:%.2f",tot);7 J  u* Z' L8 J7 s& b+ v
                }1 x4 ~0 T9 _+ P1 j  U- U, Y
               
8 J  M- e% k' T: [               
/ f8 x* P2 [- ~6 ^& i        }; Z( g; _8 e& Q9 e7 Y, J
$ L2 C8 n) s9 {  V# {

8 H$ c" T0 N" S# B* K}# p8 S5 @' c7 P# N; q
TQC108
  f& d- i  |% s0 K) \4 Y1 mimport java.lang.*;
& A" i+ P3 W* P; J) U  v& w5 w2 R( L. t
public class TQC108
8 M+ |8 J( n8 A$ Q1 \{
4 X, U8 j0 s! d2 F  public static void main(String[] args)                                         : F1 q% w0 U: N" _: Y, R* u; b
  {
- W8 n  ?: G) A3 n" t( }% f   for(int i = 1 ; i< 10 ; i++){# j. D! c" m4 [6 u. M& N3 `$ {
      for(int j = 1 ; j <10 ; j++)
1 N* m9 |2 C3 R+ t9 d         System.out.print(""+i+"*"+j+"="+(i*j)+"\t");' {$ @8 C( D  g; H
      System.out.println();
, Z8 `0 c$ ]% }# v4 S( u2 l   }; f+ O, K8 h2 R' @6 Q
  }
! s: w. o( x. a* q! F1 \7 {; `}
( ~/ M$ O8 C2 f& k) \1 S
% a9 E+ k! s9 d8 X2 J5 d3 ?$ Y6 q5 S( {3 M
TQC1094 u* Q) ^" |# K/ r* {( r
public class TQC109 {
/ f& N$ X6 c" w9 }, H1 b  public static void main(String args[]) {
8 ?6 P5 d- a9 A6 [1 {+ Q    int r;
2 V' b8 N6 i& B& `# U( w5 o   r=(int)(Math.random()*100+1);' e6 @7 [! f6 B& t" y3 q/ q- U$ x4 c- |
   double area = r*r*Math.PI;6 a* o/ n: b& z/ T1 ]
   double vol = r*r*r*Math.PI*43;( {# s! [7 p) Z' v- X' |
   System.out.println( "隨機產生的半徑為:" + r );
, [* c5 g, ?% y9 G2 }1 m- g   System.out.println( "計算後,直徑為:" + (2*r) );
! k$ V0 X; d+ C, {; D6 b9 r   System.out.println( "計算後,圓面積為:" + area );
. C, @+ _7 d6 g) z$ f! X4 N   System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
8 K" q' \) ~# N" s: o" x0 T, y   System.out.println( "計算後,圓體積為:" + vol );
2 h- f% X  {$ e6 E  C) o& a8 q/ y   System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
/ {6 ?: m4 t: j7 g3 B7 Q$ m! R  }: h% D( e4 L+ s, e- J& E
}
3 `9 S+ c' ~5 Y1 x2 ]! p; q0 m8 O1 ]5 u2 ?* T; H  q  T

2 [! z7 s; `( DTQC110   
( A6 C0 J4 f' s! _( {import java.io.*;; O6 g" k+ ^' o, S7 V
import java.util.Date;
% ^) [, D* g9 r$ D5 ]* U
' N# u. O( j7 {8 _    class TQC110{
* f9 K6 n, d9 z1 b        String items[][];! ], D% ]' g7 T4 U( J& W" ~
        long start, end;& p1 u' n* e; z" ~. L
        Date d;( O4 D5 w$ |5 E3 e4 P& B+ `
        BufferedReader br;5 C! H6 F9 d" h& e

/ ~2 n* O& A6 S1 C        public static void main(String args[]){9 k9 E% B2 d7 t. p/ @, P* G2 J  a
            int total = args.length;
" d6 \. m4 B) ^9 g: P% B3 R            int pairs = total / 2;6 w' ?5 p8 O. O9 m$ i" s6 S
            TQC110 tte;
. Y5 J+ u6 k; G6 O: h            if(total != 0 && pairs != 0)$ l: K! \8 h4 [4 z
            {5 t8 A) Z' ~2 ~. A* ^
               //get value from args..) n( F/ d% O' g0 j
              String[][] tt = new String[pairs][2];
- r  _' b; ^3 d# s5 B# ?2 p6 F2 x              for(int i=0; i<pairs; i+=2){
. ]3 }, Y  v& R' y                      tt[i][0] = args[i];3 i4 w8 j6 ~8 C2 H8 g2 @
                      tt[i][1] = args[i+1];
3 {/ O4 O+ y2 S1 w( M              }
1 p0 e: g) x8 Y- ~              tte = new TQC110(tt);
& G8 r  ^* l8 K1 L' U, ]2 y, q) W            }else" R( z0 s' M1 X3 W
                  tte = new TQC110();# Z- G- f5 M0 H0 u
            tte.start();5 q6 j' V1 f) ?1 k4 ~
        }
" ]6 i4 n: B- b& H
4 Y' v" k5 d6 H' i: `& e& Y0 U        TQC110(){
, P9 L! ]0 W! x, P6 i            items = new String[5][2];" Z, I3 v. q0 ^1 K
            items[0][0] = "電腦";
) d+ k+ S/ P# [            items[0][1] = "computer";4 h6 G( Z. f8 Y- f7 o
            items[1][0] = "資料庫";4 r9 Y% w: D! j  A& L
            items[1][1] = "database";
7 y6 k0 H* T# A1 a8 n! U" M7 V            items[2][0] = "語法";5 ?4 }! ~+ E4 c8 m$ F/ o
            items[2][1] = "syntax";
& A! [. u1 M# f            items[3][0] = "學校";
$ N; l; b) o+ E6 z7 Z            items[3][1] = "school";
* S3 X* \+ Q8 T  l% P            items[4][0] = "假期";
9 Q" O, n2 O7 x2 z& r; c            items[4][1] = "vacation";
7 u  s% |1 f! G% ?8 ^& {            //make default value0 p: l1 t  }! ^4 y" \
            br = new BufferedReader(new InputStreamReader(System.in));: n, S  R4 n4 |
        }
/ R) X* b& S4 L" b; f                   ! c( F) f" L$ P) H8 Q- o6 B3 y" x
        TQC110(String[][] it){
1 f  U& p* ~0 \3 a( D            items = it;
* T* t$ |2 }$ M4 x4 {+ R" |. K1 F            br = new BufferedReader(new InputStreamReader(System.in));
4 \3 P! n, X6 G) {* j+ P% z* J/ T        }
5 f8 n' G, ~& U  l                     `- }# ^( H9 r# p3 Q5 j% T+ X, `6 P
        void start(){
$ n: ^9 M: p3 [7 b, L. h, |            String ans = "";) e. a8 `* ~9 I2 P& _0 l1 [9 O- Z& ^
            int correct = 0;      // 計算答對題數
% T3 `* O: L% ?. i+ F! H6 F2 V' d/ z- p" v            d = new Date();
) ^( M3 G8 A. h% N7 {- r# @* @# [            start = d.getTime();  // 開始答題時間
* k" g; G) P; ~; v2 Q- I6 t: c            System.out.println("請將題目的中文詞彙翻譯成英文單字!");) z5 T" ], k6 E( _, ?
            System.out.println("輸入英文單字答案後請按Enter鍵:");
" x" y1 u/ D# d& I2 @1 l6 k0 b2 ~            System.out.println("           ");
6 f6 k3 \/ `$ |! L( O            for(int j = 0; j < items.length ; j++)
  q0 X% P  N3 |) N& x5 k* z6 N            {
& x! |6 D- o3 s* j! I- g                System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
- S$ j2 r6 @8 Q  s                try{
/ P  v( S2 `% Z% k% C1 e                    ans = br.readLine();0 k! A$ c4 z4 X# V
                }
4 }" Q5 K; W, A+ g- p                catch(IOException ioexception){7 O( b/ r& x( {' j- h
                    System.out.println(ioexception);0 \8 x) x7 r3 _: E! K8 }6 t" f
                }
5 y5 V* {9 J! ~" b) p                if(ans.equalsIgnoreCase(items[j][1])){
) G( s: H8 V+ }6 i( B  v# Z) U                    correct+=1;
7 y6 Z0 h1 z9 b- |7 `, Q                    System.out.println("答對了!");
% z/ `  @1 I' X0 c# W7 }  L: A                    //count correct) W  S4 f7 t5 I8 k9 e; G
                    //ouput correct message
  [" [8 N9 B( h0 R6 [; j0 a. Q; z                }else{
/ a$ A6 B4 t' j0 g                                System.out.println("答錯了! 正確答案是:" + items[j][1]);, o5 \9 {* N4 @
                    //ouput incorrect message
: x+ i- b( Z9 E) l  @$ i                }
, N1 X. V7 M7 D- R. U            }- s3 U( [' X* e' v, D' ?  J6 X# x

* x) t  U% @3 b            d = new Date();
+ h! N# x- _, g: t- Y3 @            end = d.getTime();    // 結束答題時間( E9 B* j9 L& q5 k
            System.out.print("你使用了" + (end - start) / 1000L + "秒,  在");( P( y4 ^  r$ |. W2 M1 v- x7 [8 s5 X
            System.out.println(items.length + "題中答對了" + correct + "題");
+ j! b5 l6 V6 s/ X6 z3 I  [        }
# b( v9 J7 x) u8 @0 n% t2 o* g    }

返回列表