TQC104
7 p+ u( k1 O6 r# Epublic class TQC104 {7 Q/ Q# v' ]* H
public static void main(String[] args) {
4 h* k: x v$ H6 V5 Q- w# P- l int a[]={0,1,2,3,4,5,6,7,8,9};8 r2 |4 j4 r( g1 p+ `' ^; r
boolean check=false;8 Y" z" s, m. ]2 s; F
int i,j,c1,c2,c3,r1,r2,r3,x1,x2;
, n' X1 H4 `7 k do{5 \. \2 m( h. `9 C, {
for( i=1 ; i<a.length ; i++){2 Y0 ?0 X( l* U* @
j=(int)(Math.random()*9)+1;& c7 X$ \: z# Y# B& q- T
a[0] = a[i];
2 l4 A; d! v! M; O9 _- v. F) i/ N3 P a[i] = a[j];
# B9 G$ W8 `$ e; i7 u4 m, U0 ~7 C a[j] = a[0];! Q( n; q) e+ y0 A1 O
}
5 f3 b6 A3 e+ o: g' L# m& @0 S- `- j$ N# ^9 F* r7 c$ B
c1=a[1]+a[2]+a[3];
8 g1 b2 J) T& t, w* |( |" p8 k c2=a[4]+a[5]+a[6];1 M" m& i" Y4 Z" P0 W. Y5 S
c3=a[7]+a[8]+a[9];
: X+ y0 x; ]" p r1=a[1]+a[4]+a[7];
+ [6 b/ \% [. W3 ~ r2=a[2]+a[5]+a[8];0 f' l3 V+ g: N6 _5 V8 z0 Y3 q
r3=a[3]+a[6]+a[9];$ @. W; N, `5 H4 z/ u/ L9 d. Y, L
x1=a[1]+a[5]+a[9];& v# J0 L, N5 x ?4 L
x2=a[3]+a[5]+a[7];; }; ^. g# ], `) h' B& R5 R2 p
if( c1==15 && c2==15 && c3==15 && r1==15 && r2==15 && r3==15
# r& E+ I' L# t5 @+ J && x1==15 && x2==15){& A1 v# [4 I+ _
check=true;
$ ], Z/ M0 {9 D, L: F7 n }
# p2 e5 e) z# w) p$ b6 I1 T }while(check==false);
, B U6 e- {. e0 Y System.out.println("答案為:");
. X! o, g5 O% f) i$ h% {
* E+ H, M: Y5 p. `' y System.out.println(a[1] + " " + a[2] + " " + a[3] );6 I$ J' d# S. s7 p6 j
System.out.println(a[4] + " " + a[5] + " " + a[6] );# k9 G- @# f7 ^5 t% T0 s
System.out.println(a[7] + " " + a[8] + " " + a[9] );
8 D2 I$ l4 ^+ [1 N+ O' h5 N5 `
: w8 r$ J1 L O, J System.out.println("不論橫向縱向及對角線加起來的和都是:15");
$ I4 D- N# B% C8 g4 O( R5 }9 x+ c }
& D- o1 h! }, W; A7 Q: Y$ @}
2 i6 d4 s' L5 ?* V5 M1 h# f' ?7 w: W( A1 [, x
# C2 `9 y/ ]+ o% a
" |1 v# J4 ? K @" a6 ]. I( G& ^TQC1050 ~$ K# |- ?" p' z! x6 q
import java.io.*;
* t! W0 h: s! G/ O. |% ?public class TQC105 {' }8 j5 y* Z: o4 ^& s0 a2 i
1 i$ ~3 N1 [, T, Q
public static void main(String[] args){. Z% q" p4 Y& y: |, `, P
try{( u- X9 ?: Y$ S( g+ A& X0 {8 K
int row,col;
8 i0 R, C0 s6 a# T" @" a int i,j;
) m4 E& Y% @. W( c: l String tmp;9 a K+ t1 v7 N) T
int aryA[][];
# x! Q5 W5 R# ~ int aryB[][];! \! d* n; g& m" `! @
BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
! {. a. a( f: I; W8 h- @4 m 5 K- x( f8 K5 P! u
System.out.println("請輸入陣列列數:");- [8 z% L; q# p5 \
row = Integer.parseInt(bin.readLine());
' K v5 ]9 m& J+ [ System.out.println("每一列陣列裡要幾個數字:");
. y! J7 U% L; q7 J1 e) R8 p5 V3 _ col = Integer.parseInt(bin.readLine());
6 Y1 b3 M/ @5 E# w- A7 l / U4 g {. @ I( m( V
aryA = new int[row][col];
2 v8 K5 x. M+ ~0 E: ~ h5 W2 B aryB = new int[col][row];
" F( b% Q# s& E- A: Y% Q- {6 K
/ x7 `- h1 C( t% r- q/ ~2 }. A0 D& z for( i=0 ; i<row ; i++){* s: c' D* S8 t
System.out.println("請輸入第 "+ i +"列");% i+ x1 Q, f9 V6 k' }4 l1 f/ v* [
tmp = bin.readLine();3 S" z- R' |. @- _9 k
String[] strA = tmp.split(" ");% i. [8 Q: ~( k2 N4 R6 C8 E6 E
for( j=0 ; j<col ; j++ ){
: n Y& {: m3 W7 A- W( @ aryA[i][j]=Integer.parseInt(strA[j]);" m# M6 B* j" ~ K
}% {) [3 o: T3 n N
}
9 e6 S+ ~7 ?( b7 {3 F for( i=0 ; i<row ; i++){6 L8 w8 p9 Y U8 Y+ F3 q' z6 h+ j
for( j=0 ; j<col ; j++){
7 I# Y7 D+ `8 p5 n& S aryB[j][i]=aryA[i][j];4 |2 i% M9 K! A" L% F
}
2 L+ u2 `9 K9 a2 A9 Z }
+ V' K: _; r) r* X( Z$ L * B, h8 X. T/ x( {! t; m9 R, ?/ p
System.out.println("陣列經行列轉換結果");
0 H i# P$ b/ M/ U: v3 \ for( i=0 ; i<col ; i++){- ~' Q: D4 x' m) \9 M" X2 a
for( j=0 ; j<row ; j++){
0 K5 M) ~# V1 k( A- z) S5 r System.out.print(aryA[j][i] + " ");
0 ], e4 b& f$ Q6 u1 w+ e1 B$ ^ }: S( l& ~, V; |: U9 K+ c
System.out.println();
: P4 ^' Y/ j9 Q! z | }* i: f u$ G1 J% M: B. ^8 C0 b
}catch(Exception e){
! d1 B% t7 T5 X6 J. [" s' t System.out.println("請輸入數字");. B4 m+ J6 ?5 J3 t: X% p
e.printStackTrace();
) s- D5 p! [6 O" i' _$ _ j }6 r% A0 ^3 R9 I
; ]6 m3 Y% I0 t+ ^5 O0 K3 i9 s
}- I( X6 i5 g% @3 a3 g* o0 Y( x* i
}6 G0 Z' V, U- T( T) r! e* l( I
3 V8 H1 k$ O$ @, O" E4 O
$ M# R# K, ]0 Z, i0 L2 N* Q
TQC106
& \$ V$ F. O, r& Rpublic class TQC106
, x. f/ g! B2 r, f; Y{% E8 s2 r2 b* {
public static void main(String args[])
( d( @, O9 I) Z' G4 d. B- K {
( @0 v. K( E. ?0 V5 g p int sum = 0; 6 Y! E$ G3 V( U* M# M+ A
int j = 0;
& m4 Y% l+ f" s! D7 c3 K int k = 0;1 z- q# B9 [; Z$ F$ w' g% S
for(int i=0 ; i<args.length ; i++){
6 ]5 c% v) ~- |4 F9 o try{
" M! s# z: _# L" O3 m \6 W0 ? j sum += Integer.parseInt(args[i]);, F5 {6 J) j e4 q6 a/ |4 v4 }
j++;
8 F2 y* Q0 u3 b6 k2 Q }
! ?% x$ L, e# O: F |6 { catch(NumberFormatException e){
. R* Z7 U! ^9 Q! ~ k++;
5 M* @7 R1 p+ E4 p2 U0 C }4 e7 z4 I# \3 T7 c
}
5 ]: D7 c; F* r, [ System.out.println("數值之總合為:" + sum );
% _7 r/ e: K% b+ P) D3 Y System.out.println("非數值個數為:" + k );
$ L) M3 \" R, v5 n+ f/ _ System.out.println("純數值個數為:" + j );' O0 e( s h+ d h* x
}1 S3 [7 M I: n# k6 l( F2 M4 o( J/ [
} |