TQC1076 _ J5 T9 p1 I; p1 l
public class test{+ c' m5 {. l: M. E; v! c8 ?, X. @
5 q: H2 Z# T3 o8 y6 u Y4 U public static void main(String args[]){
0 Q# |, C+ d W
; g o. g! ?9 N1 c( t0 x% ~: ? //0 1 2 3 4 p2 q5 _1 K# ]3 e' L
//1 1 2 36 R, G' H# ~ S, F+ P! b
//2 1 2 3, o" A( \4 H* c H. x
1 b& D( U. P2 ~7 A# z
float tot = 0 ;6 ?- M# V5 g5 ?) y) l9 r
for(int i=1;i<args.length;i++){2 }1 U7 \( i) R( O* n
tot += Float.parseFloat(args[i]);
% _6 t2 d( X7 E8 z* ?8 V }
0 ], v# q4 @9 x5 [' K tot /= (args.length-1) ;
2 K9 c4 C# d4 Y" x! i. u- Z! Q3 [
% i( ?( l' N& D( _* G if(args[0].equals("0")){6 A, s( d" H. ^/ x/ f& V( F. c: V
System.out.printf("平均值:%f",tot);
y- y9 Q l0 f }else if(args[0].equals("1")){* ~. u6 f# s9 V' }9 Y
System.out.printf("平均值:%.1f",tot);
* T6 }. J2 M; ~' J% X! S* @" g }else{; [( T; }! A3 k" G: f
System.out.printf("平均值:%.2f",tot);$ ]8 I2 C3 \. w6 u. y) [3 Q
}
9 b' {+ T d8 {' o# c/ l; \) L $ @& z+ N* H% B- g5 z3 h$ \ ]8 T- ?
3 w, v& W0 y' f; C
}
# D' f, F m* z6 @2 h( |9 q& M7 V# ]4 `
# g" g6 k( @7 C! Z* @}0 h3 S9 q8 Y8 F8 x/ c/ J. v& G" N
TQC108$ k% t, C, d5 R" g4 ]- C; p% @
import java.lang.*;
, t7 Q2 x; H7 y2 h0 e' U3 t; s% t9 e4 M# x! c6 _5 D; G
public class TQC108( u, ~' }, k& S( S. p9 O/ Q
{6 u9 x' f4 |" A% k
public static void main(String[] args) $ I2 f8 B6 c0 {5 E7 w* Y2 c" o
{( @" {. T, i8 M4 G) r7 N0 Y
for(int i = 1 ; i< 10 ; i++){- K: _5 J9 |* T. A1 A# C8 f
for(int j = 1 ; j <10 ; j++)2 W9 D- t+ F6 V, B; ]& R- D
System.out.print(""+i+"*"+j+"="+(i*j)+"\t");5 [4 b2 K, l# L; G
System.out.println();
! x3 ^0 Q4 R m0 P" J K% r }! T0 w8 {8 D" G
}/ Q6 W4 _' a, W: v% S u7 s& Z
}" ^1 v* |- h3 [, a! W; p+ K
* m, U8 I0 ~$ Z4 K3 ]5 g* J
' E" A+ R" W# ~3 @* eTQC109
" I! h1 G! i5 n( A3 Y; q* E" e: lpublic class TQC109 {- B+ V' `7 o8 |: X9 v
public static void main(String args[]) {' G+ I) A! z+ K. g5 \
int r;
" l% x; n1 ]; k V4 _ r=(int)(Math.random()*100+1);
8 K: q; }6 [1 h double area = r*r*Math.PI;
, z0 M% D3 @7 ~3 h double vol = r*r*r*Math.PI*43;" {. X7 }+ j- F! {# X; \6 y+ W
System.out.println( "隨機產生的半徑為:" + r );- h6 ]5 {5 ]' {
System.out.println( "計算後,直徑為:" + (2*r) );& v" j0 ]4 h1 s* e/ d
System.out.println( "計算後,圓面積為:" + area );
2 D; b3 g7 w' j2 b" j6 v$ Y' e System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);! b6 [8 z6 W: o1 L
System.out.println( "計算後,圓體積為:" + vol );; f' {9 H$ G5 C& \
System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
4 o* O: V2 t! o1 X$ z) x# z, Q }
& D$ A: x" ~" a$ K0 m: m" U}
9 R' i. c- ]. i N. @! G9 {6 N! ]' L; O$ a2 X5 E/ J
% @3 ]* S& ~1 JTQC110
6 a2 b, M! ~3 }7 ?# x% W! L! pimport java.io.*;
+ R# `- \$ R. W' cimport java.util.Date;, o( ~* R7 I3 S
# e+ p6 o7 w7 e6 M
class TQC110{) a+ N# L; f8 d1 o4 q# u+ ]
String items[][];$ E6 o. u0 t- t) D
long start, end;
2 S3 Q- B- V/ b" i1 ^* ?' h- o Date d;7 {8 H, b3 O2 f. x, d5 o# A4 Q
BufferedReader br;/ A8 s" D8 s2 ]" v
1 ~. D5 L! j6 H+ h6 ]8 n, g2 T
public static void main(String args[]){
9 r- f/ @& W) ]2 S+ Y- D int total = args.length;4 H% k. r8 c7 b% O! y o4 H+ s
int pairs = total / 2;5 U: l: f2 k w* z- J
TQC110 tte;' O! P$ q% s( n" a0 I/ r% C {
if(total != 0 && pairs != 0)6 |8 j8 Y4 S" |/ F
{* s3 f0 w& w) B
//get value from args..
/ p+ h( H* g+ G' b6 k% g String[][] tt = new String[pairs][2];
; Q& f ]/ ~' K4 u for(int i=0; i<pairs; i+=2){
; ~4 [1 A2 v! M2 [3 H6 f tt[i][0] = args[i];, |$ M4 ~, B3 ~* q3 F
tt[i][1] = args[i+1];8 P% R. m, |. k
}( t) S, A8 x2 x# D9 }' G3 Z3 k
tte = new TQC110(tt);
( ]7 J5 \4 Q3 ?9 M* Y2 T- [0 A; E }else) _* J( U# n, M7 q4 A
tte = new TQC110();
" _1 r5 x8 k/ A! j tte.start();
+ d- R# r0 J( B" k& U { }
4 o; }9 |. Q/ e7 @6 P# T2 b: A6 z( h9 D2 S7 e+ u
TQC110(){
" q+ j+ r2 f; m. H items = new String[5][2]; t, v: O# C: B [! w, \: ^
items[0][0] = "電腦";, X M5 g& u5 X& D( U$ J& l4 K; `0 G. C
items[0][1] = "computer";
3 z9 t& T! V+ u. Z: U% L! b items[1][0] = "資料庫";! X2 g. S" H' t" _, Q% G' S
items[1][1] = "database";7 y" d2 y! P% L6 C2 I) {
items[2][0] = "語法"; G- r6 O+ W% Y+ H
items[2][1] = "syntax";* x9 N( j' D/ d5 x1 E
items[3][0] = "學校";9 Y! m. I% {8 |% |' c
items[3][1] = "school";: ?% D6 m' o8 i" ?
items[4][0] = "假期";( ]$ Z! ]3 A U( E; C& W8 n; h
items[4][1] = "vacation";" K V2 N) O) x) n2 x+ }: e% M4 T
//make default value# H) E5 y0 e, p0 W% i: V5 q. d+ h9 V
br = new BufferedReader(new InputStreamReader(System.in));. S* S1 m B2 I- T1 K* }9 s0 y
}
% c/ u! j8 {2 Y
: n/ r" Y& i" @ TQC110(String[][] it){( ^; C5 r/ f2 |1 D; ^) F3 B
items = it;
! Q/ P2 H* N* ~! |$ W7 q br = new BufferedReader(new InputStreamReader(System.in)); G V! [3 y. s& l; }) r
}
' J+ ^/ M7 e* U, z0 \0 h% n
( |6 A1 z7 }# k, u# i. } void start(){2 i) E$ x& E7 J9 j$ V0 }
String ans = "";" \# b0 i6 U+ K* s$ {- t
int correct = 0; // 計算答對題數
9 W5 v# }: {1 A; e d = new Date();# D( A" p2 w7 }" |8 B
start = d.getTime(); // 開始答題時間$ S5 F7 @5 e! S# q" U
System.out.println("請將題目的中文詞彙翻譯成英文單字!");
2 B8 v% K& [/ K; \) z. l System.out.println("輸入英文單字答案後請按Enter鍵:");
( f/ I! c2 H$ C9 P1 j! f; d System.out.println(" ");7 n$ e0 k" L w. w* |2 @% \3 _
for(int j = 0; j < items.length ; j++)
1 Q3 z; }" P1 d1 U; ]! c- d {) V9 i% Q6 H- v) [% `: b- c& i
System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
7 i9 W+ l3 d+ _8 } try{
) A! p* W1 C& E* T* O' \2 q! Q ans = br.readLine();- ]5 g3 c7 _3 D6 c( W# y' E# w
}- W# s; K. F" S) Y0 C+ H0 C9 `7 d
catch(IOException ioexception){1 s3 V4 b5 N) }' n
System.out.println(ioexception);
* O/ e9 Y& F+ V }0 E8 m, s* y, x$ g5 y1 a
if(ans.equalsIgnoreCase(items[j][1])){2 d7 t' R; ^+ ?& F+ @
correct+=1;
3 ^0 z/ M7 s9 x4 k, A( f System.out.println("答對了!");
" P6 Y5 Z0 o" c. g8 J+ s5 o //count correct
0 r6 [ y. Q# [7 I //ouput correct message5 o5 \: \! c9 o X h
}else{
' M' e& f% g1 Q! v7 L2 a" S5 i System.out.println("答錯了! 正確答案是:" + items[j][1]);
2 _* S- K% _7 N- O" N7 |! @0 G6 m //ouput incorrect message
) n9 R# t' o2 {4 r& k }
8 r0 e0 J/ _1 W }
# }0 c( Z! S5 e
6 z5 k9 ]% M+ M6 I0 m! w7 O6 m d = new Date();
# }; G- p5 y: Z* I end = d.getTime(); // 結束答題時間5 F; t: p8 W$ {8 U# L( z
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");
4 l6 M5 t' p4 |8 ~1 J System.out.println(items.length + "題中答對了" + correct + "題");
' ^: h! ?! v# ~8 y! f8 Y4 P( V }5 p! I: ~( c: Z9 c. R% y1 H- \3 _
} |