TQC104
+ V4 _3 H. x5 e& e7 z* s9 y* \' t) Npublic class TQC104 {- R* i' i' _: c7 T$ I5 D$ _8 x
public static void main(String[] args) {
7 i3 r( U) k5 k& u* ] int a[]={0,1,2,3,4,5,6,7,8,9};8 B, E! C+ n0 H! \: h U
boolean check=false;
7 P9 _" N& n$ I. i3 S$ b; r" i int i,j,c1,c2,c3,r1,r2,r3,x1,x2;
/ P6 z& d) \' g9 b do{
9 S d) B" F" I/ Y6 z- k for( i=1 ; i<a.length ; i++){
: h; c6 D' c5 P+ H3 T j=(int)(Math.random()*9)+1;
- Y3 Y3 _" l3 n4 V a[0] = a[i];
. L) p9 n9 L6 q% o a[i] = a[j];
& h7 b( I- r6 k" h8 l1 t8 J6 k a[j] = a[0];
! l/ W, {# S' W7 N0 r }2 L. [/ b9 |* [7 }- @
- s1 u# C2 U c# C8 p
c1=a[1]+a[2]+a[3];
2 b4 N) ^1 ^; ^' R6 ~7 p% g c2=a[4]+a[5]+a[6];
' N" \/ m% w/ X" j O c3=a[7]+a[8]+a[9];
, `8 W; N6 N: G8 x r1=a[1]+a[4]+a[7];
4 p3 u0 A, n' l( P r2=a[2]+a[5]+a[8];
5 z3 H* l8 M" P2 E1 _ r3=a[3]+a[6]+a[9];& @ |8 w F7 I. q4 ~
x1=a[1]+a[5]+a[9];% ]8 W5 z0 `; S- f. {' t
x2=a[3]+a[5]+a[7];; R, B! ~+ M# p7 P! ?
if( c1==15 && c2==15 && c3==15 && r1==15 && r2==15 && r3==15
' o- ~- @7 ~9 Q' d Q' y && x1==15 && x2==15){
. |: U" G' Z' W4 ]/ F9 M' d check=true;
! P. M: `9 L7 g# w* P } f% j/ J5 a- C" h7 s# _* I* C
}while(check==false);
, H6 ]- ]# m# { System.out.println("答案為:");
# j$ c) O' W& Y' K# @" h
+ {% h$ d7 x' h/ r9 L: J0 s System.out.println(a[1] + " " + a[2] + " " + a[3] );
& h7 w) H e: n# l% q# U1 t5 J5 c# G3 s System.out.println(a[4] + " " + a[5] + " " + a[6] );
6 s) f E) N1 `- x System.out.println(a[7] + " " + a[8] + " " + a[9] );
$ `. L/ W( a& h: H, P U0 h& D- i
2 r* M5 Z4 m- N; B. j/ o( g System.out.println("不論橫向縱向及對角線加起來的和都是:15");* B, T/ l) B: |. T. {- }- w" O
}4 u, P: o H; t3 t. p% l# _
}- v5 \- Q X# h4 G/ W' X
, P4 v1 O9 j8 p3 g9 q5 Q: O. N% L8 A
! J2 ]; ~$ d3 d* Y6 a' ^7 g! s+ h: I# L: S1 M
TQC1051 I3 U- Q- K/ m
import java.io.*;4 b0 g$ z1 x: x8 Y0 j. s
public class TQC105 { c) u4 K1 |; N( G$ w+ C
/ Y3 n; h8 n: G. m/ z0 z+ ~2 o# I4 i
public static void main(String[] args){: N7 x3 D5 V, g c
try{
: @+ |: S3 V- e3 d4 r int row,col;7 `4 j( z0 y; Q/ Y: M8 g
int i,j;9 d& e4 y: V+ T2 x' {+ ]4 A
String tmp;8 x. e+ [: y7 I4 m) V
int aryA[][];/ j% C# u7 r/ T' P
int aryB[][];, g. P& \' E! ~% L# Z x8 ]; d
BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));7 m6 l7 A3 b' E5 q1 S' `
, Q% i2 S4 u1 D) D
System.out.println("請輸入陣列列數:");' \- ?+ F3 _ ]! ?# W
row = Integer.parseInt(bin.readLine());4 p9 V+ M4 s% w( ^1 J" ?
System.out.println("每一列陣列裡要幾個數字:");9 |- o* a8 p1 c+ z
col = Integer.parseInt(bin.readLine());7 N# ?; }3 ]2 }% y" ~* Y7 |$ d
/ }$ C3 _; w3 b2 W; P
aryA = new int[row][col];
8 r0 i& E1 g2 E9 [ aryB = new int[col][row];1 w" }0 Q% {9 T9 ^4 {+ V
4 K; M9 e- s5 f( O for( i=0 ; i<row ; i++){
/ M; f! ~0 b& s; |/ [/ y* z3 C+ D6 s System.out.println("請輸入第 "+ i +"列");
* V( F+ H9 t% z7 ]8 ?% G tmp = bin.readLine();
5 U) e% S2 n$ |5 s String[] strA = tmp.split(" ");
4 l' ^3 G) n- e for( j=0 ; j<col ; j++ ){
: f/ w' {" \( d6 y aryA[i][j]=Integer.parseInt(strA[j]);
8 F& i" R2 }1 y' F2 L }
: R4 `( W+ }- z- |, ?4 w }( j- c) Y& ^3 y$ n, h5 |; \% F
for( i=0 ; i<row ; i++){
0 {$ ]( i7 E+ p8 m for( j=0 ; j<col ; j++){
6 r$ F3 K% X6 @2 m! r6 l aryB[j][i]=aryA[i][j];$ l( ?$ l/ G3 |& |6 }5 J# F m# [
}( h1 ~: d8 p- J) V* V6 W4 f7 {& K
}6 } i. z8 I/ X5 f2 l" s4 z& G
E* h( S& B0 \% k; C% e- I
System.out.println("陣列經行列轉換結果");
/ L5 | O# ~8 L6 l for( i=0 ; i<col ; i++){
# y# ^) F9 u" ]( ?% }$ a3 L. P3 Y- w for( j=0 ; j<row ; j++){
! F/ _7 \* ~8 h* h5 h System.out.print(aryA[j][i] + " ");
# b% k" O# T, [0 i }' Q: q, J7 V1 v6 P
System.out.println();
2 j( P8 A9 w( L5 L$ E t7 O }) ^) x# t# W3 t8 d% h
}catch(Exception e){
7 b. G8 e! D5 `/ `3 V8 w System.out.println("請輸入數字");
( I' T; u1 E8 K. C9 T e.printStackTrace();
5 S$ ~% q. t+ N; k/ {" Z }4 R; ~6 [$ i( J7 \
7 n( b( F, U. ~' F0 X. d
}" \3 U4 t; G% X3 Q& j! V
}5 Y3 J" D& Q2 s5 a: p
, x" S5 c3 [) b; ~7 e 8 w9 w* s6 ]' r) ~
TQC106# G- Q: T, j: f, M
public class TQC106& x" ?# Z9 N0 s$ K
{
) J: G0 V5 ?. V1 F8 P' [0 a public static void main(String args[])! a- F2 G( d+ R6 ?, i' B5 G
{
$ ]+ y: { k6 R6 l int sum = 0;
% j5 T0 l' i5 F3 g! R int j = 0; ' N7 Z% [( m$ x* S$ B
int k = 0;
) B/ I6 G' ]0 ]( C7 C for(int i=0 ; i<args.length ; i++){
, Y. g9 @0 s( i. v0 f j% R8 j try{
( R3 z0 S1 v# W: J8 F3 M sum += Integer.parseInt(args[i]);0 k9 v, q+ c, B2 W
j++;
# u+ \# u4 D; A% l }
( Z1 ?. l$ q- t) y catch(NumberFormatException e){
1 F1 l0 Y( p# V6 z k++;$ p3 P O }0 p2 F. B: z9 a
}
7 V) ^$ B9 o/ u3 `' |; Q+ o- k }! u5 f |) W2 u& P9 @
System.out.println("數值之總合為:" + sum );' {' d$ y# g. Y$ v7 e
System.out.println("非數值個數為:" + k );
: ]; ]! l0 Q8 F& ^% {7 N9 k$ u1 ~ System.out.println("純數值個數為:" + j );0 e+ H; v. `) h. R C& }% ?
}
& x/ K9 U5 S1 L} |