TQC104
2 {: l {+ v% [( C% Z% Q( ?public class TQC104 {+ Y( f& I8 ?! w5 Y
public static void main(String[] args) {
3 F+ x! K9 d. _( ?/ g7 \0 b int a[]={0,1,2,3,4,5,6,7,8,9};
6 e2 z: c7 U# y. r5 r boolean check=false;
; j& I" Z" j6 ]$ c int i,j,c1,c2,c3,r1,r2,r3,x1,x2;
]( A+ D" O" _& [9 h2 { do{: H6 p- J; n7 \/ ~1 e7 ]
for( i=1 ; i<a.length ; i++){$ M' P+ n5 _- [1 \4 d
j=(int)(Math.random()*9)+1;4 t" V- n. {" A. o" V6 o
a[0] = a[i];
! O' q5 B5 F% K8 D7 O a[i] = a[j];
( j+ W6 J. D. q# U1 t$ Y a[j] = a[0];: i( a h% J; [: Y
}. M% `0 b1 q$ K3 P2 R N
2 ^2 f* c2 I0 C2 j7 @( l5 W c1=a[1]+a[2]+a[3];6 J$ N5 r5 T! _/ u, B
c2=a[4]+a[5]+a[6];
( w$ x7 z6 L- Y! q c3=a[7]+a[8]+a[9];
: r$ B a- l0 u r1=a[1]+a[4]+a[7];
2 e: u% h0 }/ v2 K0 N- Z7 H# D4 L r2=a[2]+a[5]+a[8];4 h% v9 }; d% g* D) n
r3=a[3]+a[6]+a[9];9 S& a# E5 `; A5 w. Y
x1=a[1]+a[5]+a[9];
5 t6 I* |3 u4 L- ~8 g8 q/ H x2=a[3]+a[5]+a[7];* {% d+ l/ f: B' A
if( c1==15 && c2==15 && c3==15 && r1==15 && r2==15 && r3==15/ @ \& R+ G( i5 ~1 w. {% g. T2 X
&& x1==15 && x2==15){0 B: P* H+ v4 [" i' r
check=true;) E) P# A, B& K# m) x7 l
}
# S+ O+ N, ?+ |' t! l }while(check==false);9 V" ?" r% ]. S: a' Y. U0 j
System.out.println("答案為:");) c$ [% c9 C3 r; a0 L3 j. k/ y
7 _3 m2 o; l- `. ^9 A) t System.out.println(a[1] + " " + a[2] + " " + a[3] );! B; s' T2 U. r, ?
System.out.println(a[4] + " " + a[5] + " " + a[6] );
8 @3 R# h0 Z R3 u0 y- B ~1 y System.out.println(a[7] + " " + a[8] + " " + a[9] ); r5 P# ]3 ?( ~4 T: P; h
+ B! `# G i0 v. @' L+ O
System.out.println("不論橫向縱向及對角線加起來的和都是:15");5 Z( }8 c3 T/ W- C5 s% U" p
}* }0 L# |+ M3 z% O3 T1 u; C
}
/ [0 I, Q# v) `3 _( |( r
* S; U j* o' l& M- R
1 Z( k4 G$ F* d
`9 ]! A D4 k' dTQC105& }8 ]1 \' f, r5 _" m8 o9 O3 Q7 l
import java.io.*;& Q# U* p/ q) }) g
public class TQC105 {
3 s7 B+ r1 {7 e1 b& W2 E% A( \
' G/ g! K, e: E1 J3 ?, m public static void main(String[] args){9 j+ [: N' C6 z$ E
try{
0 i8 x' [! m8 |2 A6 f5 y% a& D int row,col; _* |! G" M8 j/ I
int i,j;2 P2 N) n; o$ H5 n% H+ U2 H, {
String tmp;
# j9 ]0 c, T4 V) O int aryA[][];
8 N3 k/ X7 g5 C) h! J0 |( c int aryB[][];6 K$ ]# w8 ]2 S4 p
BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
) c2 o; s4 A* y5 |7 v) z
K" d8 w& d; k" J x: D' Q System.out.println("請輸入陣列列數:");: ?% \0 \3 c0 t! F9 v5 w- \" e9 r
row = Integer.parseInt(bin.readLine());
; {3 U+ D# Z# W' m System.out.println("每一列陣列裡要幾個數字:");$ ~1 V- J1 C" L+ h5 N( I
col = Integer.parseInt(bin.readLine());
3 q" E, Y& {6 }+ l& G* b6 ^ - G0 g' S. w9 |9 G
aryA = new int[row][col];8 v x& i7 q& B) {1 d
aryB = new int[col][row];4 p; y" ]- x4 w, V6 c8 h1 k
I+ \" r2 ]* \2 _' l: _7 K" [ for( i=0 ; i<row ; i++){
1 P+ f/ a9 G7 V4 a5 t# A2 r System.out.println("請輸入第 "+ i +"列");
; Z% m7 N* k! ~' |, A tmp = bin.readLine();
/ W- z# j) X% s) ? String[] strA = tmp.split(" ");
* z( @8 a6 F$ t. [7 l1 Z, O+ L# @$ G for( j=0 ; j<col ; j++ ){8 v* j4 Y! a/ a) w/ `! ^* v. n
aryA[i][j]=Integer.parseInt(strA[j]);
% k4 m' I- ~; I }# F! D% P/ G4 |# p6 |0 ^1 h
}& g8 Q5 t: \" w
for( i=0 ; i<row ; i++){5 F9 j8 _+ X9 T7 C4 ]1 \2 d% b
for( j=0 ; j<col ; j++){
( ?' g: p* k, q; U1 G- w4 n6 v aryB[j][i]=aryA[i][j];% j( R9 m- w: N; V% ~1 ~: q3 p
}3 \& d1 _% f9 v6 k9 D, r
}
# i: V2 _* D6 C; J5 j7 e/ Q5 z
9 Q2 Y9 a: [ B: W6 D2 K System.out.println("陣列經行列轉換結果");
& c; v/ i* r' l. p for( i=0 ; i<col ; i++){( a% o# \( @* p, Y& z) w; N
for( j=0 ; j<row ; j++){7 r. O; q" J& w6 q3 j8 f' t
System.out.print(aryA[j][i] + " ");! @3 K/ a; {! N3 {" H1 G% d
}# C. M, i* Z- X$ ~' u
System.out.println();
3 D6 I. ~( v- L+ z4 z* Z }
4 @( M; K& d% B }catch(Exception e){
, f. \( d4 ~2 P% S m System.out.println("請輸入數字");6 i: o5 W( ?! e! X8 d S9 P5 @
e.printStackTrace();
5 M( z1 e0 V \ }6 U* B- j3 C. k- m9 W' d' k5 K+ W
5 S* O* ~ V+ f" K- }* `
}8 m' K E; H7 w/ u9 D! H; D
}. Q. c6 i7 }: d& P
% E. R4 y/ h4 m* ]6 S% V
2 B& \7 E- x1 U/ |" [( iTQC1063 b, @1 y! E2 j. @. B0 U! @
public class TQC1067 l8 B9 r) F; e, ]
{
, f" C/ q3 P2 U- [) O9 b' f6 A9 K public static void main(String args[])
% T) M/ y' ?" v; X4 L {
+ k4 P- N; O; V Z# f; r# O int sum = 0; " i% O/ w7 G- L1 G( N# [: Q, K
int j = 0; 5 w8 k5 O$ b/ P K$ x
int k = 0;0 y6 g3 C/ `0 e& c
for(int i=0 ; i<args.length ; i++){
; N! c* R4 X! m s" `6 i, y1 k try{
2 q9 g/ x7 e7 G: b: k6 _$ N6 g. o sum += Integer.parseInt(args[i]);+ T2 O8 f7 @5 N* x3 {$ x
j++;
1 Y0 z- f7 R9 h; \; T" a. C }
+ k7 ]+ F2 e; L; X6 u, W: [3 d3 F5 g catch(NumberFormatException e){7 }- a1 j9 _4 ]5 @+ ?, h
k++;$ r/ @" \7 b3 q$ r! n
}
9 w. H |( }' f0 o5 N }
8 t7 G! z. a) r System.out.println("數值之總合為:" + sum );
% u. B) u" Z2 J7 ] System.out.println("非數值個數為:" + k );# o+ O7 j, D7 q# X
System.out.println("純數值個數為:" + j );
' W- w/ Z1 w% { }
' l! J' i, u e8 |2 A/ B" P6 `/ ^+ p} |