TQC1076 y1 s0 Z( t% u, p+ t8 F
public class test{
: ?9 G# b- E/ E. S2 C8 T0 T( d3 V/ @9 C6 s
public static void main(String args[]){! b! i. z) W3 Y e) g& f
, ^) j+ u# u* ~2 ?9 ~% I
//0 1 2 3 . H3 \1 g* B" C2 L0 y [$ @9 R
//1 1 2 3
2 q! Z0 D' _! f& d" q7 ~ //2 1 2 33 q# L6 r8 O/ z2 \+ q' l: ^) l% Z+ J9 t
# B( a E+ @) ^: L+ ?
float tot = 0 ;
+ o8 S. `3 _" r" l# ?# S for(int i=1;i<args.length;i++){
4 Y$ L1 X, R- u. _) E tot += Float.parseFloat(args[i]);2 T+ z) ]8 U; e3 J. ]
}; M4 b& R' l0 C* M
tot /= (args.length-1) ;
/ {7 D/ L3 K$ u0 C ; P f6 ~: n( e0 n( j
if(args[0].equals("0")){
7 q- e! d3 V& N5 u2 \! X: R System.out.printf("平均值:%f",tot);
# W& p$ M" ?7 {! X3 w }else if(args[0].equals("1")){% ~3 k) a/ _' t8 d- `# i
System.out.printf("平均值:%.1f",tot);
! k* h/ a; F+ N% h4 A! F! N- I }else{& G/ m9 x: w& t, f
System.out.printf("平均值:%.2f",tot);
! g. r1 R+ E A# D, } } c, N6 D/ t( r% d1 K
% z0 V1 m# d% f5 U5 r0 k
+ a( d6 c6 m4 d( l
}+ x" Z9 }% c7 `
- D3 T) U `" B% Y! O2 c3 j
. J5 P" @" R3 Z; e- T, y+ j}
0 ]+ C- A5 ?* t; |TQC108
: G( h; K1 ?5 n; G# Bimport java.lang.*;
- N+ X! U( u' {0 g% |( G
% }* e% a7 M& g2 X: lpublic class TQC108/ m R d0 C; t2 X" A8 V. T7 `
{
$ V' }$ o3 J2 ~9 a' `, q public static void main(String[] args) % h3 T" U; l' d v U
{
, ^3 r; L- W% j2 N- x% C9 O$ t' J for(int i = 1 ; i< 10 ; i++){
! U) U4 @0 f& p7 e2 g$ v: ] for(int j = 1 ; j <10 ; j++) y+ ^% p3 c8 }
System.out.print(""+i+"*"+j+"="+(i*j)+"\t");
; [7 l* C8 X' U System.out.println();3 I: n9 P1 G% Q- ?. |* U& b* T! x
}
B- G. V& U! k5 _ }
5 W3 l4 c' }9 x}
4 w, A0 v9 }4 P
! z W, N% \; @3 m4 y
# I8 v# ]3 i1 H( e( Z5 e4 pTQC109. `) T, |; w( N/ m- k' x
public class TQC109 {- W8 Q4 h+ c5 n" e6 r( D1 G# G
public static void main(String args[]) {
& Z" }8 n3 R# ]$ Z$ v int r;
4 _; {# |+ @5 o4 r r=(int)(Math.random()*100+1);, D+ M/ C' p6 W6 U: C
double area = r*r*Math.PI;
( `% R- o v0 u) d' V double vol = r*r*r*Math.PI*43;
3 x4 e' K( |, w& | System.out.println( "隨機產生的半徑為:" + r );1 H: w2 X: V m
System.out.println( "計算後,直徑為:" + (2*r) );, C1 l/ m4 Q9 u: [$ e* _
System.out.println( "計算後,圓面積為:" + area );. ^6 k* R# O2 ~0 L
System.out.printf( "四捨五入至小數第1位,則圓面積為:%.1f \n\n",area);0 R7 _" a' o; s5 `* i- o6 h* D
System.out.println( "計算後,圓體積為:" + vol );
. O) o' Q6 B5 D1 u7 g System.out.printf( "四捨五入至小數第1位,則圓體積為:%.1f \n\n",vol);. K; z1 \- t Y, N$ u( F; D
} {7 W9 e" }/ J0 e7 p
}
; ~4 A0 Z$ S M9 I8 D! c. y! `0 I) C2 J, Y+ Q A
" m% @0 l- }% D* r" R- d: O: S. D
TQC110 : K3 U* T9 W, U/ R. C( w$ q/ d! {
import java.io.*;; Z; f! G+ \: ]6 K3 g- _
import java.util.Date;/ V! K, S2 q3 l v. W+ o# G( a/ q# @
$ B4 U8 Z4 S1 P9 s' q& x class TQC110{1 o* Y- t+ i% t+ N: Y' U9 b
String items[][];9 G1 v: o/ ^& ` i1 d. _3 T7 Z9 \
long start, end;! W0 B! j/ A. |: k. K
Date d;" a' c$ N; l1 ~
BufferedReader br;4 N) `0 F, g$ Y* D- m; @# F7 I
+ p! ]5 C8 N/ p6 Z public static void main(String args[]){
1 m6 N1 w5 v1 c0 Q4 W int total = args.length;
: T4 S/ _2 B: q( S' S int pairs = total / 2;
# p! F" E6 f5 w" i! t. ] TQC110 tte;0 R7 }% h% J; p, ]4 O2 ~
if(total != 0 && pairs != 0)
# R8 `" S2 {4 D, r8 i" { {( x |/ F, y. b
//get value from args.., y7 g' k. n! c, ]2 ~& f$ X8 l
String[][] tt = new String[pairs][2];
! L4 Y$ \# z9 X% P" B for(int i=0; i<pairs; i+=2){
* F; O5 Z- j# C1 B0 X. { tt[i][0] = args[i];$ y3 x! |$ B) W! z% ?3 l
tt[i][1] = args[i+1];; W& t- z; P% g3 H8 x1 u6 U1 v
}' c( R% Q# U s. Z; G
tte = new TQC110(tt);
1 G- T' i+ l; m8 H7 M+ m8 A; @ }else
& ?& e& R3 B& c* N3 l" f, e/ u tte = new TQC110();
% z3 J) u! V. k, P% @5 H7 ?" A tte.start();
+ k U- H. d1 E7 {( ]* @9 C9 O' Y5 D }7 y- H+ O$ c- M
/ Q: F+ K A; o TQC110(){
8 b0 L6 F# ~$ O' h8 `3 g9 f- y items = new String[5][2];
8 b0 q6 p0 Y; V$ E+ O; M1 Y S items[0][0] = "電腦";
! C8 e$ s6 S3 N1 C6 V- a" A items[0][1] = "computer";
+ M5 B. F3 R: E/ q6 M/ p items[1][0] = "資料庫";/ o% o/ q8 f* I
items[1][1] = "database";/ `# V9 Z! O0 T3 Z
items[2][0] = "語法";
: B8 _2 i# o, _$ o8 \ items[2][1] = "syntax";
' b( \3 E# C; F4 m5 r- a+ u items[3][0] = "學校";
' u/ S8 l% }1 u6 a# u! l/ ^ items[3][1] = "school";) p( U9 m* J2 d3 A; W' T8 d0 O
items[4][0] = "假期";( |6 b8 V; P: q0 Q6 ?& {: R
items[4][1] = "vacation";1 F% F# ]; U% @* T" D7 ~
//make default value
' r) ]8 X0 H7 d F1 k1 @6 o br = new BufferedReader(new InputStreamReader(System.in));
! Q: T/ g/ Y: m& s/ N& T4 V, U }3 S: b l0 J$ ^ M* K2 f* R
5 ?4 {9 h$ M+ d' t
TQC110(String[][] it){1 V: U2 v& _7 O/ g/ H4 N3 V1 O/ L
items = it;1 Q4 c3 _2 u5 V8 y! \
br = new BufferedReader(new InputStreamReader(System.in));2 y# k6 T7 C4 Q( w4 V; z$ O' q
}2 K* m/ g! n3 A% } t
5 Y$ C5 O x5 L: Q; T
void start(){
3 T! \6 Z/ d" ?# W' } String ans = "";
1 _" ] [+ O0 @' p int correct = 0; // 計算答對題數$ x3 J* _# T0 f4 j4 t
d = new Date();
# e9 W* x1 M+ _( W8 A. x8 n start = d.getTime(); // 開始答題時間) v/ q: ?8 p9 l9 q
System.out.println("請將題目的中文詞彙翻譯成英文單字!");* @$ F( A1 y; m0 ?; E
System.out.println("輸入英文單字答案後請按Enter鍵:");
% H1 B- [. p, H# E+ A; A, p+ M System.out.println(" ");0 P' C* l/ u: b2 K
for(int j = 0; j < items.length ; j++)
* T: N3 e' l# f {' A" ?; K1 `% D0 _" M$ e
System.out.println("第" + (j + 1) + "題__ " + items[j][0]);# K5 ?* r$ J! L1 i$ V# K
try{. n4 a1 g, e1 H5 [
ans = br.readLine();
0 m; o& m6 F: C# n }
3 }" G1 e- N2 | catch(IOException ioexception){
6 { ~6 e' \# Z. }% a System.out.println(ioexception);
, e2 Y$ b8 z; Q5 X }
' h/ K5 h' ?# i, w- _ if(ans.equalsIgnoreCase(items[j][1])){
4 Y$ l3 s$ `; v9 [- F2 A correct+=1;" c; k8 u& G) L& v
System.out.println("答對了!");- M2 B( `2 p0 p: ?1 B
//count correct) I0 q" A. r+ ?) {" ], {$ |
//ouput correct message
4 p: R& K& b7 ^1 r/ V9 s }else{
2 W) m$ f7 C7 c9 ]$ r0 s, Q System.out.println("答錯了! 正確答案是:" + items[j][1]);) m+ I$ A4 N$ a- Z3 r% L* c8 i" ]# E
//ouput incorrect message, F, j. V' x8 ^, m, q' p) H4 C# h
}
, D2 ?& w3 p! j& H7 A7 D }
3 ]& U+ Z! n: D1 E6 H C( m' ~9 ?6 ~2 o- U/ ?$ W
d = new Date();
7 h( ^4 F( j6 Y; T2 m end = d.getTime(); // 結束答題時間# j, j% C0 G. q
System.out.print("你使用了" + (end - start) / 1000L + "秒, 在");# |- ^. u, {- ~4 }+ u! ^5 l
System.out.println(items.length + "題中答對了" + correct + "題");
$ x. C; o2 w w2 c( w0 V5 V" X }
s( c2 V ?8 ~& J } |