TQC104
# _9 A' T3 w5 g# g' @# i2 Gpublic class TQC104 {: S" B3 q! T( u) h& l( N
public static void main(String[] args) {
" R$ u# `5 M2 X i* B int a[]={0,1,2,3,4,5,6,7,8,9};
& k0 W. u5 v V" y; Y boolean check=false;+ }9 i; ]- k8 j; N0 V
int i,j,c1,c2,c3,r1,r2,r3,x1,x2;$ r1 O+ q! D ~2 ?% x% G
do{
) d- \, p; ]; Z1 g$ P+ T1 ^ for( i=1 ; i<a.length ; i++){
% N6 B8 I K. z2 |* |: c$ U) A j=(int)(Math.random()*9)+1;
/ c# I% O. s. I! T m& C) E5 p7 b- Z a[0] = a[i];' [2 r2 p0 t5 C+ _. n3 T
a[i] = a[j];" R/ h' e5 F8 L O/ A8 y% Z: i1 d
a[j] = a[0];
8 O5 s7 N2 Q4 N. x, ]# N' F }# B6 V3 E; g2 H0 M
7 E8 Q4 j k7 r9 _2 W3 m' G/ j c1=a[1]+a[2]+a[3];
$ _* s/ ?/ M0 s/ ~% {6 x c2=a[4]+a[5]+a[6];
4 ~8 W/ T1 B5 Z- M. u c3=a[7]+a[8]+a[9];
+ S5 J' E7 X) Q5 V8 Y r1=a[1]+a[4]+a[7];
8 w! p& D' f1 |9 H! o r2=a[2]+a[5]+a[8];
u0 C8 l- H1 a8 J* M$ q* C- {. [ r3=a[3]+a[6]+a[9];
) p$ a6 z( L# V9 W# d7 M. j" R x1=a[1]+a[5]+a[9];
6 I2 L1 v, B8 T- \/ X9 Z6 p x2=a[3]+a[5]+a[7];7 k- m# j9 V x W7 `
if( c1==15 && c2==15 && c3==15 && r1==15 && r2==15 && r3==15
- k% R; X- k: s S) w1 t+ m && x1==15 && x2==15){
+ n, B2 n- z2 p* U( c check=true;
+ r6 G' O. z! x% S7 y# \/ h }% G- G5 F- w1 i6 P( M+ Z
}while(check==false);- t& k4 h- u. j8 i8 H: }3 h
System.out.println("答案為:");
, X3 o' o/ ^0 I o, O6 W: O( z
* v5 U9 g8 v" L. A) ? System.out.println(a[1] + " " + a[2] + " " + a[3] );; U+ k( |3 S, n% y H* J2 G
System.out.println(a[4] + " " + a[5] + " " + a[6] );
: t1 ^7 N. I" |# b: _ System.out.println(a[7] + " " + a[8] + " " + a[9] ); u6 h" A* W# }8 W# u, v g$ r
[2 s# U2 I, V* y
System.out.println("不論橫向縱向及對角線加起來的和都是:15");
, q7 M8 W$ D# `- \( c6 h) o }
& _2 O- C* D, \5 i! H4 |- Z1 B}
8 Z8 N- j: S, h
8 ]+ i# c) v& n# y: l& J( f& _
8 E- O6 E* o8 n8 S3 i: B% m, x: t! C' Q4 {
TQC105; u+ `) n/ b- ^- n$ T. t
import java.io.*;
( k7 s8 T9 E* O; A5 t* i; p) L% X4 qpublic class TQC105 {
" m+ s5 q. i2 y A, Q4 A. ]" C9 P6 |) ?: w
public static void main(String[] args){& A s( H! I# N1 A. V$ `
try{2 G7 \. `3 G3 {9 U1 ?0 _/ k6 Y% i
int row,col;; u Q" I% V* s6 Y
int i,j;
* w! l" g, X2 S* ^4 G$ O String tmp;5 r+ m6 `2 |0 g" f
int aryA[][];& u* a+ ?( a6 n) `
int aryB[][];
e* ~8 ^: D) J BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));" E0 K) c+ m" Z6 ]. y
' n5 p7 w# \" p2 @) I+ @0 y System.out.println("請輸入陣列列數:");6 J2 u, T1 Y8 X6 C! t9 F% s" o/ e) n
row = Integer.parseInt(bin.readLine());% X5 v/ H9 B0 y* |
System.out.println("每一列陣列裡要幾個數字:");
- \- q' u& i/ _ col = Integer.parseInt(bin.readLine());) ~9 P' \" B2 b( {, w* V$ A4 l
: q) ^& K2 t1 ~* ^) V3 Y3 o$ {
aryA = new int[row][col];
5 g( L, `* b, ] aryB = new int[col][row];/ E" r1 d# g8 D; J8 W0 z
9 Q0 c1 r' o9 n
for( i=0 ; i<row ; i++){( E+ E: u8 I* p/ I( A6 S( Z
System.out.println("請輸入第 "+ i +"列");2 N$ K" ]; Z! ^: c- x9 r3 h
tmp = bin.readLine();
9 U9 L1 h' i1 C' ? String[] strA = tmp.split(" ");0 n* L* s2 t2 F8 B$ b4 K0 K$ h% O
for( j=0 ; j<col ; j++ ){! U! p5 n) a8 j7 w
aryA[i][j]=Integer.parseInt(strA[j]);6 b- B6 U! O: @' h! X" ~& G
}9 m5 [7 E D7 }4 Y6 s% @+ P' Q- P8 Z
}
1 a! X* p5 ?# n for( i=0 ; i<row ; i++){; _$ Y) |. o) a8 z8 n1 s4 x
for( j=0 ; j<col ; j++){7 v0 r/ V \+ J
aryB[j][i]=aryA[i][j];8 s) C3 Y0 O( r
}( l) R/ f, |( ^5 ]
}5 N( H$ J" s6 ?- f
) t/ R% P! j* y6 _, k" u8 h System.out.println("陣列經行列轉換結果");
9 y7 D$ d& X( w1 w1 f) s+ a for( i=0 ; i<col ; i++){) F/ {% I& E8 w) m& u& Q
for( j=0 ; j<row ; j++){9 H" l! q' O) n* y$ A5 X9 [$ C
System.out.print(aryA[j][i] + " ");! D* G3 U2 a; @( i' w- ^
}# W" \+ c; ~+ Q) g# F1 ^
System.out.println();
$ f6 ?8 K' C: I m( n* \ }
% ^. x) \4 D6 @ }catch(Exception e){9 `+ _$ d, N4 T; T, u! E6 ?
System.out.println("請輸入數字");
0 Z1 U, W0 K x# s: o( ~2 r: y e.printStackTrace();
`0 {6 z/ E3 y }
y8 \1 f$ _* E' r: }1 D6 A2 u+ D! J3 M7 h! a; n% n# q: d
}6 p3 }. j c5 b0 U% y
}
% M' Z4 }+ D8 v7 r* ]! t, s& t# I' C* L3 Q' t( x) C
6 w( g$ b# I6 I; a
TQC106: W9 x! p' @6 c; K2 c* J
public class TQC1069 c6 v, |* w& ?, b7 B0 L, H
{
9 M, k& a/ ]. M8 I$ h7 M9 D public static void main(String args[])
0 C$ n. w) y$ ` s9 P( N0 W' y, j( M {/ {$ S. {5 B- p9 ]( @; g
int sum = 0;
# D" X+ ^! I! U+ t6 @ int j = 0; 8 G8 N% l+ {6 ~6 | [% g
int k = 0;+ [( c( Y* t4 w- n4 @! a6 @
for(int i=0 ; i<args.length ; i++){9 A& ~) Z, H$ n0 {& ]
try{1 t, Q/ g2 _; V
sum += Integer.parseInt(args[i]);" l, e8 N7 G( B1 g: n
j++;6 Y8 f5 T/ v3 r1 E1 o; `
}3 K- q& J: s( e) S
catch(NumberFormatException e){
4 k7 I, d/ U& l& t- x) l- P* z3 s k++;- q- o1 N2 I* ?2 i6 t P- [
}
; r) Q9 l. W( K+ O }
0 Z+ [& ? s% R" t System.out.println("數值之總合為:" + sum );
. i- B8 a. n7 I$ Q _ System.out.println("非數值個數為:" + k );) b6 P+ e" D$ l# f- l3 @7 @
System.out.println("純數值個數為:" + j );7 A# e" I; H$ W7 I% f
}
5 D. V6 A2 v" S+ n$ V} |