TQC104+ A. Q/ o( {' K* {! G' E* p; h! v
public class TQC104 {9 M5 _# V) P( n7 I9 e, y
public static void main(String[] args) {
2 m, ^4 H* s5 b7 s. H6 ]7 G, V int a[]={0,1,2,3,4,5,6,7,8,9};: s0 y5 n1 S* ^3 b$ F
boolean check=false;
+ [2 g. L8 ~+ g) e int i,j,c1,c2,c3,r1,r2,r3,x1,x2;: s$ ~& }) `/ M8 N5 `4 I( }
do{7 v. K8 @0 D3 k# ?# W
for( i=1 ; i<a.length ; i++){
, c8 O! v4 K3 R; r, { j=(int)(Math.random()*9)+1;1 V. U; a0 e6 u ?' h b2 I% A7 G
a[0] = a[i];! s4 S3 O9 u% q
a[i] = a[j];* \- e/ y6 r, E. R
a[j] = a[0];9 Y6 \6 \. ]4 N R3 y7 N
}
! Y3 w, e% U2 K, Y4 h+ t
9 l+ C R4 z9 R# ^! [, T c1=a[1]+a[2]+a[3];
; G" @7 f8 m9 n6 [" ]" e c2=a[4]+a[5]+a[6];8 n* E# H$ }3 D' d& J/ u; e
c3=a[7]+a[8]+a[9];) f+ \1 E. s/ Q4 o
r1=a[1]+a[4]+a[7];4 h# r( {% q4 t. ~+ @
r2=a[2]+a[5]+a[8];
$ E9 x! m/ B' U% U B2 }$ J r3=a[3]+a[6]+a[9];, [3 H/ t& P; x2 e- S& L5 |
x1=a[1]+a[5]+a[9];
9 p0 d3 j. |4 t4 y3 g" N x2=a[3]+a[5]+a[7];
/ q7 n" T! `2 K. o2 Z S- p! }) g if( c1==15 && c2==15 && c3==15 && r1==15 && r2==15 && r3==15# ~& T0 N7 z6 p% k
&& x1==15 && x2==15){
7 l5 \. D8 o3 ?: C check=true;
1 T9 t7 \6 a/ i* U, J* a% O* h* d }/ f; m/ T, }3 z/ i$ p4 f" S
}while(check==false);
0 m4 X# M( k$ z System.out.println("答案為:");# |% S, ~: I; x4 T
9 a* ^ _0 w( U* u% T1 T System.out.println(a[1] + " " + a[2] + " " + a[3] );( g! r: J: b r! A) }: q. {
System.out.println(a[4] + " " + a[5] + " " + a[6] );
# H( Z' B8 r! t8 i9 g System.out.println(a[7] + " " + a[8] + " " + a[9] );
. y: y6 k& ?7 d% ]- M2 x5 \( q4 T9 c9 ~* n1 D- v
System.out.println("不論橫向縱向及對角線加起來的和都是:15");9 w: I {2 o+ g# l8 J& A& J
}
, ?% _4 p" S- Y! h9 G- i f}
8 |: e* Z2 W4 p# E% q i5 G
8 \0 ?- e% R' D3 Z) u5 m; I& r
" p! F/ d! [$ X( j
# x2 A6 U* W' g, F* y0 ~9 sTQC105
' v; q1 F; b+ t& k3 qimport java.io.*;
7 s" q2 b z9 s* g% y$ D: xpublic class TQC105 {, w" M- j3 Q' f2 h7 a! s
# z' Q. W6 a9 A, z, S# F
public static void main(String[] args){$ z U) T1 \ E5 Y% b$ D* z
try{
' c% X, C4 l0 q0 F7 q% H v int row,col;) i# N2 p( Z7 j, y& o
int i,j;
+ U0 q0 _+ ^" l& m String tmp;& H. `' D* ]: z/ \" ?3 G6 M6 m
int aryA[][];0 o2 F5 e6 W* s7 r! u8 t4 E
int aryB[][];
% G" H( R7 @ F% I% ?& m BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));! \1 a5 S. _* y- n' ~4 m( m
; ~5 P8 a w7 x% ~3 S2 p+ i
System.out.println("請輸入陣列列數:");
/ f; P3 O: k" _ row = Integer.parseInt(bin.readLine());
8 \9 d/ I/ n$ M. O, x, R! }% Z( F System.out.println("每一列陣列裡要幾個數字:");' c' p" K' ?) {1 A4 C# P
col = Integer.parseInt(bin.readLine());
8 a/ s J" q; S' s
. T, w) v6 c+ p+ n1 I+ h/ ? aryA = new int[row][col];
4 s+ Y. Q0 H% ` aryB = new int[col][row];6 G4 X5 W, G5 e- E' W% \, r
* i z8 T; l3 q
for( i=0 ; i<row ; i++){
( W g3 ?7 b% |3 \" ~( L System.out.println("請輸入第 "+ i +"列");5 O0 }) d$ G, I$ W- R
tmp = bin.readLine();
. @+ e6 o" ^! G" |9 k2 @ String[] strA = tmp.split(" ");, C" `4 S. k X {; \ q) O ~8 X
for( j=0 ; j<col ; j++ ){
2 X2 K2 V% C" o G* |/ O5 q1 [) M aryA[i][j]=Integer.parseInt(strA[j]);! v! M7 h! I! b
}
4 g, R. h4 @7 [! I }
" s8 P! f1 s/ b% H2 H) V4 j for( i=0 ; i<row ; i++){6 {' \% D7 k; q" ^: k) Y1 O" d# H
for( j=0 ; j<col ; j++){; K3 G( }& H& ?8 i8 _: o" N
aryB[j][i]=aryA[i][j];
) U- x5 u! r y& z# G7 X }
- Q% ?) c. B: k7 ~: k }, @, R7 _# Q) a$ v0 O; h
0 ~: B% R2 @% A5 |* |( g
System.out.println("陣列經行列轉換結果");% M; A. a2 x0 ?, K9 ]( T6 g% C
for( i=0 ; i<col ; i++){6 S9 a) O5 U, N( `
for( j=0 ; j<row ; j++){
1 j1 n$ j) q& _0 r3 D1 z System.out.print(aryA[j][i] + " ");
3 g0 p$ o4 s+ k3 A" L8 t }
2 N/ Y1 D7 l$ u M4 I1 B! E8 t System.out.println();
- |$ A( {2 l; ]. ^9 K }
t8 ]0 ^+ Q$ A# W o9 U }catch(Exception e){' k' i: Q$ ]+ G: Q% e
System.out.println("請輸入數字");
. B# ~! J0 M2 d1 P e.printStackTrace();$ C3 C. R! A7 t0 J# F* ?) [
}1 ]+ P% D# B6 p
# B% U* r: z; I1 N2 T; T5 D }: t! _* z2 y% ^+ @6 _$ Q" j
}) g( n' U& W* t9 }7 a
. G/ x$ x0 _- G$ }
& c7 I) y q/ l7 Y8 a
TQC106
% Y8 y# `8 \5 |public class TQC106
3 |- Y1 z; F9 Q' n: t' \{6 I1 J4 o! T$ i) z5 o
public static void main(String args[])
; S! c, o. R1 r1 V" W c Q {
0 E R! g5 ^0 i$ Z int sum = 0; 2 [- ^& ^1 o# q0 E% l
int j = 0;
' ?1 X, M# l; b5 N& i. x2 C y int k = 0;7 z6 u* h% O+ a: H/ T
for(int i=0 ; i<args.length ; i++){
6 B0 b! ^: E- O) ]6 R try{
) x* g% a+ D6 ?- S1 b sum += Integer.parseInt(args[i]);. N! d6 C! s c) O- M0 Y8 d
j++;7 _1 ^1 E6 [/ @5 I# p4 q
}
% k4 z8 I) O. q/ B( i) |3 Y, Q* G catch(NumberFormatException e){
% x6 n+ I+ W) Z: { k++;& J; @& \ @- p6 e9 J2 x# q
}
) W$ ^7 L) \0 ?4 U- W7 u5 X; N }
4 }$ `. Q5 C6 I# ~ System.out.println("數值之總合為:" + sum );
1 S. v& E: p4 D. w8 L System.out.println("非數值個數為:" + k );1 z* x4 x( G- \7 |( [
System.out.println("純數值個數為:" + j );
" H# n5 A; D" K9 q$ C }
/ E( C' h& d Y ^ n3 q} |