TQC107+ J2 f+ _' A, A4 i. S7 `0 s$ Z: N9 O
public class test{) I0 D d3 z' q% Z% U
: H9 P k7 K" \7 |4 S0 T
public static void main(String args[]){* d( s L0 C( `9 o
- A+ Y1 u/ L0 U! B d) {& V7 _ //0 1 2 3 " D" U* b" C, `1 N
//1 1 2 3
, Y; C8 }; j1 k2 } //2 1 2 33 W* [( `) K4 {: o
: q% \; r L) m4 z; N# d( h
float tot = 0 ;$ f3 C+ f( E4 @" L7 r3 S o
for(int i=1;i<args.length;i++){
% X! N2 V7 Z! l tot += Float.parseFloat(args[i]);; C# W1 S0 s8 X* K% Q" |+ S
}
4 U u' H7 y3 v- F. t tot /= (args.length-1) ;: c, B" |$ P" x5 \7 s
7 P3 _6 L3 N) s, U2 |
if(args[0].equals("0")){
% i& l" D( @0 L% \( E; x( Z System.out.printf("平均值:%f",tot);
+ S; J, B2 q9 ~6 W }else if(args[0].equals("1")){5 B$ M3 [* _4 Z, j3 A3 [
System.out.printf("平均值:%.1f",tot);
4 }" m; ?8 Y. _ }else{9 \9 J/ N1 g3 f
System.out.printf("平均值:%.2f",tot);4 n- Z7 q' L) V8 k1 T- ^
}3 u% P, P, [3 f. r3 v
2 K8 w9 k8 x. W$ y( A7 w 2 Q! K- ~; b# P
}
; O9 l& |9 C6 b7 R( m, I K0 }# @: _0 j2 P
, M! K" X s) C7 W, d1 X' a
}" t5 u$ a" R7 V0 P
TQC108
# P7 _8 J# w: _import java.lang.*;
) b- `/ M1 m4 x, ]& k( b) {' d) Z
public class TQC108
2 H5 D( y3 t8 }5 Y2 v ]! r4 @) x{
0 T) k. ?! t/ u$ C3 V public static void main(String[] args) 3 @' F" }# e2 F
{
, z X' U/ Y3 i' G for(int i = 1 ; i< 10 ; i++){
1 \0 I; |0 R$ U( \/ w1 }4 b6 z$ E for(int j = 1 ; j <10 ; j++)
/ \* Y0 z3 I. {/ E System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
% d0 P' I4 y: b. ] System.out.println();% m% x0 S; P2 q" A
}
) M! A3 _8 h8 p, l( {+ p+ _% ^ }. Y; K2 w0 M' J- o/ X& O
}
. ]9 o3 G7 Y% J9 g# x
2 G% D2 J! S# e; p+ P9 y# T, n7 p, r# k& F! {( `3 b/ [& R- b% J
TQC109
. k- Q9 d( w) ~! r+ K: Ypublic class TQC109 {: s0 [6 A; v5 B3 l; \" b
public static void main(String args[]) {
7 h1 b; h* Q2 N, d1 m" W int r;
/ h" i- `% N: S! k r=(int)(Math.random()*100+1);
. g% E0 }) T1 |, z6 Q: V) B double area = r*r*Math.PI;0 q$ Z" U& O; K0 h* V
double vol = r*r*r*Math.PI*43;" c( A) [" V' A3 H
System.out.println( "隨機產生的半徑為:" + r );
, G. [" D( W0 j! N0 j _' W8 |5 X System.out.println( "計算後,直徑為:" + (2*r) );# p" F$ V' v# n. M6 ]. {
System.out.println( "計算後,圓面積為:" + area );
* E3 C+ a( i1 z1 W" M& g | System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);
7 d5 N2 a3 W5 _- M7 o System.out.println( "計算後,圓體積為:" + vol );; }; x2 ?) J( g$ m) X
System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);
9 g* f# c( J: S3 p2 e2 `8 V }
, a2 W# m# I: d! j1 j4 d8 h# Z" c, l}9 G3 J6 C& b6 a
. v6 Y) Z& M! F: r: ]1 r
6 s2 u4 {" }0 o% DTQC110 1 G/ n5 L) K Q/ m" m# a2 ]' B, T
import java.io.*;1 R( f6 f& K% m- U$ X" P
import java.util.Date;3 L8 d0 c/ d9 J- m+ ?' O$ D
, Q1 q9 u; N/ b
class TQC110{
A8 Y) V+ P$ d String items[][];9 G |9 R0 T [
long start, end;
+ t5 h6 [: y: f" r6 ^+ j Date d;
; p$ p6 ]8 P# X BufferedReader br;
( V& E# ?5 U8 N9 V* K9 O/ x' D( G5 s4 Y/ H5 f/ I. u
public static void main(String args[]){. B/ I, A( C( p7 A7 `6 `
int total = args.length;
1 v. B, t- n0 R4 ~8 s int pairs = total / 2;( @) c9 W, J( M6 L0 s% ~! w
TQC110 tte;8 K* R3 M3 J5 B$ W- T* J: h
if(total != 0 && pairs != 0)4 I& ]2 R0 ?+ x5 X
{
: @5 ~4 @# b5 q //get value from args..# J! l$ B! M7 ~. p8 U1 A
String[][] tt = new String[pairs][2];
" w) U b6 v! M: |. c0 w3 Q$ N for(int i=0; i<pairs; i+=2){! B/ g* {4 L* b/ f1 E Y. |
tt[i][0] = args[i];
, e: Z' p; l" Z. [, \* G tt[i][1] = args[i+1];+ ?( N" J: G; C/ O. f
}0 U" W" l* h8 Y2 r* U" {" }
tte = new TQC110(tt);! Z) U, `+ w8 R4 ^; R0 H: |! S
}else- _, L+ a0 v- }
tte = new TQC110();
+ P* ~- n- h6 a" i/ {: e6 K% Y tte.start();" H7 F+ c$ u4 ?& u8 j" W: R' R
}
) k, Y8 X5 h1 Z, E+ r+ u" v
. G- W Y+ I7 A! @5 A8 ?( N TQC110(){% s3 N3 Z. ]) U* w, t A1 S8 s4 ^
items = new String[5][2];/ P3 o" _7 ^9 l* h
items[0][0] = "電腦";, Q/ S. q! J0 c- d; a7 `/ V$ V& l
items[0][1] = "computer";
I# Z3 q; P$ y% Q% D: C! B items[1][0] = "資料庫";1 K& I# v8 x7 B8 g
items[1][1] = "database";
3 H8 q b- Z: o7 }$ r items[2][0] = "語法";7 m# q `) Z4 q0 r0 r4 y
items[2][1] = "syntax";
$ b D+ f# k% ?0 O( C1 ~. y# {: x items[3][0] = "學校";
7 ]& Z- `! z; ^' A" o! G5 x items[3][1] = "school";7 q7 D, q6 s' @
items[4][0] = "假期";5 m2 l1 y5 L/ O& l2 W
items[4][1] = "vacation";
3 ^; c4 G+ Y4 a8 L5 x& D F //make default value9 r$ s8 F% ?% x) [8 n
br = new BufferedReader(new InputStreamReader(System.in));
2 X, Q: g0 R& ]4 J, |2 t! n }
4 S4 ?2 P. A2 {3 t- _ 2 ] j' Y4 a# T! X$ z5 _
TQC110(String[][] it){8 @, V. X. b0 O/ W M7 ~
items = it;
3 M1 }6 ?7 W1 V2 u br = new BufferedReader(new InputStreamReader(System.in));
! g# ?. v0 _- u }' n9 D; l/ _ \% C( z5 J- Z. z) f0 R o
. f: ]' D! e% R+ i0 e A8 P0 e void start(){
% ~$ c( p7 U( U& S String ans = "";
- f6 T) y% v5 ]* k int correct = 0; // 計算答對題數
1 L; [" B k: F3 B+ }% Y/ B! u& z0 K d = new Date();* s. `# u v( ]
start = d.getTime(); // 開始答題時間
7 }+ j# _+ A- f9 k3 R System.out.println("請將題目的中文詞彙翻譯成英文單字!");
( C: F0 _: p" W System.out.println("輸入英文單字答案後請按Enter鍵:");* o, k2 N6 _; h4 F( y3 F N# l& T
System.out.println(" ");
+ q2 }2 p @) l- g for(int j = 0; j < items.length ; j++)
$ G+ s/ G% x4 ^6 M& F- J {
. e$ P- @* [( j" b System.out.println("第" + (j + 1) + "題__ " + items[j][0]);
7 b* D3 K' P9 j; i# D2 X try{
$ c% ^ R1 M6 M X" i# S: b ans = br.readLine();
) [% p N# V$ y. D }$ c3 i" V$ l* ^" y8 ]3 W; T4 o
catch(IOException ioexception){7 M1 g' p1 b0 N# r
System.out.println(ioexception);
2 H+ ~; A$ o3 y }
" ]" K' O5 G* m3 s5 q if(ans.equalsIgnoreCase(items[j][1])){
( A; s ^) N W! c+ j6 N correct+=1;
! G+ j# `7 X& ?" I. S7 q System.out.println("答對了!");
$ \) E" j3 L! p# W //count correct/ _; Z1 N; L+ Y
//ouput correct message
* }% G( S+ I9 F H! w+ c }else{* ]5 S |! b1 \
System.out.println("答錯了! 正確答案是:" + items[j][1]);/ W5 J& H) M, X/ Z$ w. g `
//ouput incorrect message
: j7 T# Z3 v# H. X }
3 l+ u9 M" j5 A }
: \# C( X; `& Y/ G* U5 C, S6 Y( ~+ e% ^& c, `% o
d = new Date();% {- I- h: k' c+ p& J7 w" w8 g
end = d.getTime(); // 結束答題時間: f5 M+ v: @# ~: U
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");+ ]9 ~) b3 t8 J) H9 e+ X P
System.out.println(items.length + "題中答對了" + correct + "題");! \! \- k- @7 x4 x
}
3 n- N; z3 W# |$ x- L } |