TQC104
z' c4 x. q4 V& ^/ k6 ipublic class TQC104 {
2 ~$ G% l2 c; z9 K. f; q% f' E+ b public static void main(String[] args) {( j" S7 C. K. A, R* B% K% R
int a[]={0,1,2,3,4,5,6,7,8,9};( B5 o+ d- x1 w# X( u
boolean check=false;) C. |8 _$ s$ s
int i,j,c1,c2,c3,r1,r2,r3,x1,x2;
& p( j% j: F! r$ Y: r do{' @- P9 o$ P8 j# f4 Y4 Y9 U: x7 X: @
for( i=1 ; i<a.length ; i++){- M' V! D) K4 G; h; m. s/ z0 b
j=(int)(Math.random()*9)+1;
$ h6 {: x7 `$ Q a[0] = a[i];' a) x- X' x: \/ k0 l( `
a[i] = a[j];/ [# \1 Q# D2 u w7 |. D
a[j] = a[0];) g0 ?1 Y$ p" R! f5 ^1 X% z
}
9 i7 J/ a/ M, n; L1 Z- \. M& l
A7 }# c( f' Y" x7 ^: T4 _ c1=a[1]+a[2]+a[3];
/ z' f, o5 K! d2 _ c2=a[4]+a[5]+a[6];
9 L+ |6 J# W* ] c3=a[7]+a[8]+a[9];
, y. Q. A+ Q! O* C) Q9 H7 z r1=a[1]+a[4]+a[7];
9 w. w8 i, M# s6 [3 d8 J8 a r2=a[2]+a[5]+a[8];$ Y$ i% ^+ o0 T: m, Z1 a
r3=a[3]+a[6]+a[9];7 p2 T2 F" i5 ?6 Q
x1=a[1]+a[5]+a[9];& }! x/ \* ]! J- `$ V" d2 ]8 w
x2=a[3]+a[5]+a[7];
( h/ T8 N+ |' g' h1 @$ G if( c1==15 && c2==15 && c3==15 && r1==15 && r2==15 && r3==15' p" D* {5 @" T) o: K( M
&& x1==15 && x2==15){
& h/ f/ D5 z7 |2 ]# g' J check=true;! w/ V) ^5 T- r q4 i7 O
}9 @" v+ `: x4 {0 K3 V
}while(check==false);5 i8 o, g' v: U/ y# p) `1 s3 g
System.out.println("答案為:");2 m$ D: d; Z# i
7 M) v4 k- r( f; S" M. Q! R, B5 h8 H System.out.println(a[1] + " " + a[2] + " " + a[3] );! j# C g0 l3 A# L& @+ c4 Q$ r
System.out.println(a[4] + " " + a[5] + " " + a[6] );
/ Q& g) p# `( ]0 W System.out.println(a[7] + " " + a[8] + " " + a[9] );
5 E% [+ c6 N. d$ C {7 e
G+ n. F% _' Y- E* ~ System.out.println("不論橫向縱向及對角線加起來的和都是:15");- \5 y1 N9 Z+ b% M+ g
}4 G4 I1 h* }$ }5 F X$ N
}- U0 t, N/ c# u+ d# J8 x
8 I$ r& d6 W9 s Z
. ^. b+ K7 B. ]0 ^
% u; R& k% U8 [5 i* L) k% JTQC105
+ c# [5 \' M; y+ E; qimport java.io.*;6 ~, y2 {4 b* w
public class TQC105 {
: q/ p& P. z. E# r+ G' Z! [( F6 e
1 p9 D4 Q8 C; X7 o* e/ L. w public static void main(String[] args){" W5 Y( B; ?9 h( M7 V3 O
try{
! \8 p* i9 m% m5 l; @/ e int row,col;
& g) A/ B. H2 Y! J* h3 j0 Q- B% `3 E int i,j;
6 J. k( C K. P. r+ h String tmp;
7 b8 f! {/ q3 q/ \ int aryA[][];. d' I& L9 N* C0 E$ ]5 q% ], T
int aryB[][];
) F3 q. C3 v9 R BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
5 E- X0 W5 l" R3 a/ \0 M# v
7 C- \; w3 T2 }6 d/ h System.out.println("請輸入陣列列數:");4 V3 l8 W) t4 J1 B8 t9 }1 v
row = Integer.parseInt(bin.readLine());
" R6 z' W4 [' z5 P1 i1 O System.out.println("每一列陣列裡要幾個數字:");
* n( Q, i6 x; Y* s col = Integer.parseInt(bin.readLine());! s0 F' L/ k8 w1 b; ^, U; F; Q
# ]1 ~- \ _- R8 b, S( C6 ]: P aryA = new int[row][col];" `6 i9 D% G" @0 j. ~
aryB = new int[col][row];
4 l2 X: J7 a# A8 N, n * d2 s5 G" v5 N$ n& F( d- c* h
for( i=0 ; i<row ; i++){
: }9 i* m7 B' K6 a* s- R System.out.println("請輸入第 "+ i +"列");
1 }9 }- h$ E* {% h' { tmp = bin.readLine();. A o* [! l4 I
String[] strA = tmp.split(" ");
: E1 P3 a4 ~( o0 K for( j=0 ; j<col ; j++ ){
: a+ V6 j3 ]4 s) b1 G8 `9 V, u, J! {% J aryA[i][j]=Integer.parseInt(strA[j]);
0 G5 q& ~" B% \) | }
6 `* Z6 ?- A. \! { }( j& u5 e9 } C& H
for( i=0 ; i<row ; i++){
. p# u3 {' {. @4 ~ for( j=0 ; j<col ; j++){& O o8 Y. C- m2 L9 M
aryB[j][i]=aryA[i][j];! r2 E" S/ I/ h" C9 S2 `2 g* q T, Z
}
; g) k/ C4 [0 V0 F2 |1 L [7 n }( [2 b3 G, Q2 |+ _- W5 z# s& p8 d
1 U' L U! c# A3 w. h3 I System.out.println("陣列經行列轉換結果");# Q& w" z8 I) C! T. o* d, s p
for( i=0 ; i<col ; i++){
9 {" n8 N9 z" g8 `1 o for( j=0 ; j<row ; j++){. Q" p2 Z4 \! x7 }, O
System.out.print(aryA[j][i] + " ");6 J0 c- `% d" f1 X) ^! r& P
}& l. \+ G) G8 V0 ~1 F$ }( T
System.out.println();
* E0 I; F5 ]+ L }5 Y% ^$ O) [" S: d8 i) F
}catch(Exception e){
% K4 I* ?1 i% L2 Q8 x; K& { System.out.println("請輸入數字");
0 m0 b" x0 g/ U9 V- } e.printStackTrace();
% Z0 k! x! m0 u" {. b }
" t8 z3 o8 a# r- x3 a6 E5 L1 ?3 ~1 \
}
0 H( l- v$ _; D}, ]$ I n% S: c% n8 L8 l7 N2 ~/ {" @5 t
3 y% m: F5 M, {9 @
/ ~' a+ C' I& _/ A, }2 u
TQC106
( b; n0 p% Y) ^/ V1 B, zpublic class TQC106
# V! H9 t! `; D8 f3 A) }9 I* p{: y8 P3 b, H/ o, C9 U
public static void main(String args[])
, }/ T1 H* t/ z4 v! C1 F& B {
. \% d: l* x) p6 O5 ] int sum = 0; / z F: Y: V% ], @
int j = 0;
' ^& Z1 I" G% S/ } int k = 0;
- X/ d2 G( | o9 G for(int i=0 ; i<args.length ; i++){
0 N, y' s" S2 f1 v; M3 u try{% n5 ]6 n9 _( y1 N( n
sum += Integer.parseInt(args[i]);1 P* {, g9 ~! ?. k
j++;7 S# z* ^, q; r2 t, F) H# |0 D
}4 L# y& `6 l* z J/ W; C, x+ @* P
catch(NumberFormatException e){
# a* [4 j. K+ \ V" N k++;
: I( p& `, B1 S9 A$ ^0 x }
) R: d, Y0 V5 V1 i/ I0 h }% _( p# K& @7 W) ^3 W) O m1 L
System.out.println("數值之總合為:" + sum );
+ w' E# N7 ], C ?9 v* p System.out.println("非數值個數為:" + k );2 y" X) N& u! i5 v2 a, c
System.out.println("純數值個數為:" + j );
, c/ B8 `5 P1 L U. y! ^0 _ }5 ^' f7 g9 n" a( }" d& ]4 d( ?
} |