TQC107
* B5 {& Q4 H7 d0 X% Z; J2 m3 Z8 lpublic class test{
1 K. \8 K4 I& b, H. n" u; h8 a8 K5 t$ }9 E+ J0 s W
public static void main(String args[]){% X4 M6 X x8 _. W% m% W5 H. Z0 G
$ o( j! e0 p) G' _8 R* X, K //0 1 2 3
+ F+ l- U+ i5 Q% C$ t) a- v0 S1 Q //1 1 2 39 f. V0 ~6 k% n! Q- i
//2 1 2 3
) I% f& {1 n3 }0 \3 R# E3 M 9 e5 t+ S* z( Q
float tot = 0 ;
" y4 T% l; H( P' W for(int i=1;i<args.length;i++){
4 ~# L% m. B! y tot += Float.parseFloat(args[i]);
% g4 w6 m( m: A: t0 `; U }2 C6 \2 f2 A8 b% Y
tot /= (args.length-1) ;3 V0 s- d0 T. @5 w2 L8 ~3 l9 f8 H! C
! r" h1 b, m+ u @- I if(args[0].equals("0")){
6 {! k% G, O& z" v. T9 n System.out.printf("平均值:%f",tot);
8 s; Q0 n, k" J! h9 M, U }else if(args[0].equals("1")){
6 W2 x$ L; g( a, p/ | System.out.printf("平均值:%.1f",tot);) M; @3 y7 t" ]8 ], |
}else{
( R; O5 C" F0 o# ]% c8 m System.out.printf("平均值:%.2f",tot);% J- ?; ]+ q+ x
}: s+ U3 e& [7 N" I; t% T- I9 n
6 ^2 e. R& O& Y1 K! n/ i& y$ c
8 X3 x6 k. H, U' T( n, G4 D }
: R% k1 |' B! d: y* m: z0 K
* x; W" p1 ?$ Z- l# A
, y; O% ]% o3 ~# m* b7 S! d}
2 G- D6 B2 u/ DTQC1084 [7 B7 F( p" y% T- H/ m
import java.lang.*;
* H' A! g+ W2 h; z
1 C6 g' @" D+ D1 W8 P! }: ppublic class TQC108
4 I- c1 f: l% R$ H/ M" F) C% P{
7 k9 ^7 J3 g: h, w* w public static void main(String[] args) . ]+ {( `( k* R! Y% ]
{
6 G0 p3 k2 s* m5 O& g2 C" X- o for(int i = 1 ; i< 10 ; i++){
z: q' t, \/ K6 p2 v for(int j = 1 ; j <10 ; j++)
. W# _# q4 `: F! `1 ] System.out.print(""+i+"*"+j+"="+(i*j)+"\t");/ V, P' S( T- j8 H' r- O
System.out.println();
, I8 o2 d0 e1 {( [# R# G3 D }2 M2 k0 ? r" f$ S0 w1 U
}
6 J, P6 n' {4 {# n; h( j3 x}+ B8 B: y! {# _# i. v0 ?3 P
2 X7 J: g. W0 V. |1 ]2 t* R/ Y( d e
+ o m1 S ]# k
TQC109
+ B3 ~. ^5 P0 H. \2 ~; Ipublic class TQC109 {
% G* c" |7 B8 H: y6 [$ B8 H public static void main(String args[]) {- s* u" V& x" t% i/ ~, P, U, [, K% M
int r;
4 u* P; j1 Y& O% k) I: [ r=(int)(Math.random()*100+1);
$ W$ U5 t" F6 C% j5 k# } double area = r*r*Math.PI;
' G) Z; c$ r6 \5 w. _' C4 o4 d/ ? double vol = r*r*r*Math.PI*43;# t1 [% u3 ?$ z' l/ A9 ]7 U
System.out.println( "隨機產生的半徑為:" + r );5 K5 Z6 n( R/ \+ \# ~
System.out.println( "計算後,直徑為:" + (2*r) );
$ k0 k) L; V/ I' ^* X0 C System.out.println( "計算後,圓面積為:" + area );% l8 T! O8 t) v3 i
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);* r- K( ]$ V- a! M
System.out.println( "計算後,圓體積為:" + vol ); e* L$ y% A# g; g) g
System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
( l: q: Z3 A' Q$ A }7 w" o( \5 p7 O1 \
}
: Z( m4 I- y5 A. } O2 {, ~9 u% y* `/ f8 g4 @
3 t6 `( b3 d! D1 C% HTQC110 # R7 g0 o; g0 Y4 g9 V, l
import java.io.*;# u" i$ D& l! g; X
import java.util.Date;6 i2 {. K" b1 ]/ I
4 I$ `; s* M* F- v% C
class TQC110{& J; \: h) e) g3 d* V' e
String items[][];/ u- `- K/ p- d* h% f: H2 Y
long start, end;
, G( b9 C( A8 F% h3 d Date d;- z( s8 O% [1 X) l4 }! |8 j8 u4 r
BufferedReader br;
; x \* w$ @3 Q( V5 k! d& J7 }5 D, k2 I/ F3 ?
public static void main(String args[]){
# ^ ^6 b9 k) c8 | int total = args.length;" W' K7 |) `, J3 [; U7 L
int pairs = total / 2;
% U- ^9 C& \& R& \1 w TQC110 tte;4 p& U! ^7 l7 T3 w9 v7 f8 u! p
if(total != 0 && pairs != 0)
9 x* C$ t/ h3 \5 S. y {
! s, C! {1 {( S3 Y; z2 { //get value from args..$ S, y5 c; i/ l& Q) D- u" |4 x
String[][] tt = new String[pairs][2];2 B/ x* I2 \$ h
for(int i=0; i<pairs; i+=2){0 M5 m- e- X) A
tt[i][0] = args[i];3 C& v' A" o$ X/ Q6 Y$ e: d
tt[i][1] = args[i+1];* z- S4 J4 S; a7 H W* H
}
: A5 }* e, M! U! l4 w tte = new TQC110(tt);- S. S3 b @+ _, {
}else: n! I; x! `# ^5 C' c) d0 f
tte = new TQC110(); A* T9 n. i) ^- S2 m8 O: r
tte.start();
2 s- v3 Y) C$ I$ g3 v: M }
% Q+ z, f" z. a" u
% {$ d2 S% T+ I6 a2 v% I TQC110(){
8 B- E; m# |/ L# I; P6 _# I items = new String[5][2];
& d3 c1 b" r" o* ?. z items[0][0] = "電腦";
6 Q+ a! f" `! T8 [+ g6 r2 g1 j x items[0][1] = "computer";( a9 ^' y4 q4 q% e
items[1][0] = "資料庫";
) w2 ~6 Q* Z% A items[1][1] = "database";% S6 T5 E, E8 N v3 H# \6 t! [% }
items[2][0] = "語法";
5 [% _8 _; Z& n7 ?* ^ items[2][1] = "syntax";( T5 r( I4 @. X8 M& p6 y
items[3][0] = "學校";
& a! D) s9 t. u8 i( E' e! M1 K# q items[3][1] = "school";/ ^2 w* S! ~8 T2 p" r' J9 B
items[4][0] = "假期";& j, W" z4 H! _- k
items[4][1] = "vacation";
% A& v7 \/ ~, q& V- e7 [$ b //make default value0 v3 `$ P+ t/ U/ N4 k% d, Z
br = new BufferedReader(new InputStreamReader(System.in));/ d; Q* K4 Q7 D- @! o& _5 H, i2 [0 K
}
3 ^3 X0 U7 A7 b* X9 g. G) T/ @
' ~; v* Y* F; F* {9 q TQC110(String[][] it){
+ S/ U8 H/ O0 V9 k8 X items = it;* ]& _5 x1 p% G2 j i/ m" O4 l
br = new BufferedReader(new InputStreamReader(System.in));1 a3 V" z2 e8 v
}
) e& S& J5 C5 [$ S t4 a# \
# v$ A% z" L) r6 e" D% \ void start(){
' K% u; W) B$ t3 F8 S2 j: Y String ans = "";* t7 q* x0 r/ V: H5 j
int correct = 0; // 計算答對題數4 C! k% o: i0 d8 w- u/ d
d = new Date();
2 X4 @. Y+ A1 g3 x6 K4 F start = d.getTime(); // 開始答題時間- a. P, {+ F5 @) ]2 h+ m" o
System.out.println("請將題目的中文詞彙翻譯成英文單字!");; X2 @3 x" l9 y/ U
System.out.println("輸入英文單字答案後請按Enter鍵:");
+ ~4 j$ U ~4 d X- G2 P System.out.println(" ");& }- B8 R5 ~. n$ Q/ b6 A
for(int j = 0; j < items.length ; j++)* Q0 D! \* A: [- ^; F4 Z) g
{
4 Q% u+ K! Y$ ?+ n0 a System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
: |) w4 e% M/ v try{* O* N2 P& P/ l* \
ans = br.readLine(); Z4 E8 y( M! \( b- Q7 [" }
}, m: E! w4 ~( `9 f
catch(IOException ioexception){8 f9 N* K+ y8 ?) W( `5 n
System.out.println(ioexception);/ e' q) B C. k# H) e
}# D# N1 _# {: h0 q1 ]: L
if(ans.equalsIgnoreCase(items[j][1])){1 M7 \ N, k8 x% H9 e, h* l7 x
correct+=1;
% G* @% f I& k$ ]4 y4 o7 W System.out.println("答對了!");
! s2 X/ ^& [+ ~' N, O //count correct. S1 l, h; B0 }% Z4 t$ }; D3 ^
//ouput correct message8 Z/ t4 I# c7 u' o
}else{
1 @: L% @* j% }) V System.out.println("答錯了! 正確答案是:" + items[j][1]);
+ ^# d5 V& Z- l //ouput incorrect message
5 C( E0 i. S. T/ A }
W+ o7 N. a5 \2 `: f# K. s: L6 I6 O }6 L" O& f' h* Y5 q8 @
. `( X/ c$ M" j) y/ [$ N Y% Y d = new Date();
) e/ E; i: @: Y" s9 J6 H end = d.getTime(); // 結束答題時間+ e9 Q! ^) s0 k
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");) u7 a4 k- U Q4 s
System.out.println(items.length + "題中答對了" + correct + "題");
4 o/ d- ^1 S/ v& E$ e" E }- e4 `* Z: r: o4 \+ h
} |