TQC104' W5 R h3 G. K5 H: o6 x5 C. ~" _
public class TQC104 {% y5 S: ~+ k. {1 f3 K1 k
public static void main(String[] args) {1 E& C, i3 K8 H6 C; y
int a[]={0,1,2,3,4,5,6,7,8,9};
- J* V7 F1 ~( ~ boolean check=false;
3 S1 K2 Z: g$ d8 M* V r int i,j,c1,c2,c3,r1,r2,r3,x1,x2;& \% J1 u1 V' n- w2 W0 d0 X
do{
1 [; ~& G2 G: }% K9 Y2 { for( i=1 ; i<a.length ; i++){
5 M, @$ c3 _: s7 e* B2 U6 M j=(int)(Math.random()*9)+1;
; D3 r+ [. F$ G a[0] = a[i];# M& n% k/ O# N- W* d
a[i] = a[j];
1 \9 u+ E* v8 g, E q a[j] = a[0];8 d. O: Z3 M3 U5 T" u4 |+ [
}8 ` i% R8 y6 @+ w+ B
; ]% `8 _. O Y: q c1=a[1]+a[2]+a[3];
* i7 ?- p/ o: M, E9 B' O/ ?* g+ { c2=a[4]+a[5]+a[6];
$ H7 m" w! E7 }5 B* B ] c3=a[7]+a[8]+a[9];
7 @$ c- p* G1 G$ w& T$ U1 ^ r1=a[1]+a[4]+a[7];- W8 j' w7 @/ ^1 }0 |
r2=a[2]+a[5]+a[8];* Q" }; n; n3 T* N/ f# S( b
r3=a[3]+a[6]+a[9];" w/ D' d5 u- c
x1=a[1]+a[5]+a[9];
4 ~- K. k+ M& O% ^5 ^/ y$ l! x x2=a[3]+a[5]+a[7];1 @/ X& |9 ~2 ^" l' a/ G0 _0 U& M( P
if( c1==15 && c2==15 && c3==15 && r1==15 && r2==15 && r3==15+ n u: p" V2 M8 w7 J. w. B
&& x1==15 && x2==15){
$ b+ b' G, k% k2 [' Z7 _ check=true;
8 w( s V/ X& W }5 h' b `8 i9 f" b* {5 b% X3 j
}while(check==false);
( U" U* T0 q) `, a0 h$ ^! F System.out.println("答案為:");; }* f. I: L) H* I$ F, O$ B
?3 L* ~( L, ]+ H
System.out.println(a[1] + " " + a[2] + " " + a[3] );
# n& D" e. R/ ]5 V, W; y System.out.println(a[4] + " " + a[5] + " " + a[6] );
, |8 S; B( d7 ~' Y3 @: | System.out.println(a[7] + " " + a[8] + " " + a[9] );
# ?% J/ n! @- R4 U4 E# }8 r; P O7 P7 w5 h
System.out.println("不論橫向縱向及對角線加起來的和都是:15");% c/ }$ F1 i- `7 [8 G$ W" s
}
! M" o y; r3 `+ V. K}
1 a( U/ d: x2 ~! t
6 m* O1 {' i$ R1 p; u) @2 z5 O Z7 [7 a' O* `& u
, B! S7 a3 }& D' u, mTQC1059 x. O. P4 y) o, @, V0 r
import java.io.*;& R6 W0 [" X! E( ]" h& @
public class TQC105 {& b H4 W. }& T6 w3 N9 |! `5 X
* i1 Q6 S0 _& c' o9 ?1 `
public static void main(String[] args){* R4 S" a* g4 x4 ~4 S
try{# j& a: h* r$ d$ g" C2 N8 Q4 H; z
int row,col;# C* Z3 l* ]. f& j j
int i,j;
_& f! G1 n' r8 ]1 [$ p" t String tmp;8 ^5 Q8 A# b6 e
int aryA[][];& g5 D' y7 H6 c% ]9 k
int aryB[][];8 t* K+ m+ G9 D# r. C, i8 |5 a
BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));, z% a9 D4 ^8 S2 q: J+ @4 c7 ^
, t6 z- N- a9 J8 M System.out.println("請輸入陣列列數:");
: |7 I; r5 z4 H6 w3 `3 G2 X row = Integer.parseInt(bin.readLine());
8 `. S% c3 y& Z( J: i- p5 h( a; g System.out.println("每一列陣列裡要幾個數字:");
' u% `/ [. d: ~8 c col = Integer.parseInt(bin.readLine());% }2 {7 _. I1 l; t @
' O% L* m0 h. [0 B2 w' `
aryA = new int[row][col];
# K9 _+ t0 E1 I% u) x" u$ c, P aryB = new int[col][row];& ]+ A0 k0 m9 B7 k- d7 f
( r2 n9 \) A" V, F7 T$ j
for( i=0 ; i<row ; i++){" W$ e% v6 p/ M5 b" e- R
System.out.println("請輸入第 "+ i +"列");
' h3 l- c9 b, Q5 P' i2 h* G3 X tmp = bin.readLine();
% [4 n2 ?: m4 Z! L# Z( o String[] strA = tmp.split(" ");
! R Z" j) ^2 \' E for( j=0 ; j<col ; j++ ){
5 n# e$ R8 M5 R4 s# ] aryA[i][j]=Integer.parseInt(strA[j]);: P# d6 A( X0 n' q0 T g3 F
}
) m0 W: R' j7 F/ d1 Y/ ` }0 \8 w" N9 |1 [2 x! J) G% V
for( i=0 ; i<row ; i++){
; c$ L4 P$ ~4 Q6 j6 w! l) i for( j=0 ; j<col ; j++){
7 [1 ]0 W9 G0 Q7 p8 P# c! P& y; k aryB[j][i]=aryA[i][j];
+ K9 n; Y- a4 p, z1 m7 ? }/ ]$ ]8 |6 w5 k; c% l
}6 I+ g& @# C" b
. _2 [6 n& f/ `6 k* L
System.out.println("陣列經行列轉換結果");/ u2 U4 D- `% A1 U, Y+ H% G
for( i=0 ; i<col ; i++){
- x5 a* W3 M+ B0 Z. R6 j* Q for( j=0 ; j<row ; j++){
* k2 Z+ @5 ?9 R& f) k System.out.print(aryA[j][i] + " ");1 D) `$ {- a Y: {1 F! Z9 H! a" }3 ~
}" I% ?; Z5 v$ {( y' w6 q
System.out.println();4 ~% s2 ^3 }* o8 u( y8 s+ T0 ?; p2 \
}( d: p/ _: }$ y
}catch(Exception e){
% D# r. Q) R, B6 S2 U7 g2 L' G# u System.out.println("請輸入數字");$ b: C; x! y! _& V' z4 s5 `
e.printStackTrace();: Z0 v, z4 x6 v& p
}
K- q% Y( w* n7 s; @+ Y4 _
0 A; o! h2 `5 |" D/ i }7 t2 Q# R: m. F, `0 Q" ]7 S# E
}; ^0 p7 D# c8 l/ G- `: j: W5 U
W) i2 @1 w) ]4 D2 E. {8 Y
7 @) a. G/ a: E- p8 v
TQC106
: `1 ]8 T4 q: c: |public class TQC106
5 B8 X, s1 h4 g" D( L0 d6 m{
' @& Q d6 }# `3 o public static void main(String args[])6 H+ m9 | U9 H$ a5 ]- `, @: N5 l
{2 o. e0 n0 H( c3 R3 o8 M5 C
int sum = 0; 0 O0 s& }6 u4 B8 i% y% E
int j = 0;
" X* [( s" D2 i) t+ L' c int k = 0;
# s. ?! a1 b2 q0 r# r+ h2 {$ s for(int i=0 ; i<args.length ; i++){
0 ~: K% |$ `$ A% o: j4 [ try{, ], u& }* {. Q1 o2 \
sum += Integer.parseInt(args[i]);( f* g' u* o" M9 y; N
j++;
9 f" c. f0 }; p }3 k6 l3 n8 n( q5 E+ _
catch(NumberFormatException e){: B B0 J3 G7 o/ q7 f- m
k++;
4 d. Z! i3 u2 Y1 r3 F7 R& A }
0 U& F2 Q+ C6 M3 i. I7 Y: c5 B }: F( ?" S( \* u2 G" O( d
System.out.println("數值之總合為:" + sum );
/ y, I$ q/ B9 }! `5 h" X System.out.println("非數值個數為:" + k );
/ d$ N5 X5 f0 d3 w6 l; V System.out.println("純數值個數為:" + j );' d8 U' |! H8 r% i% y% z" t; ?5 [
}
7 T! s5 p) G8 Y; N} |