資料檔:
1
2
3
4
5
6
7
8
9
11
12
13
14
15
16
17
18
19
---資料檔輸出
package chap1;
import java.io.*;
public class t0106 {
public static void main(String args[])throws Exception{
BufferedReader fr = new BufferedReader (new FileReader("data.txt"));
String str;
int i=0,j=0,k=0;
while((str=fr.readLine()) !=null){
System.out.print(str);
}
}}
---
package chap1;
import java.io.*;
public class t0106 {
public static void main(String args[])throws Exception{
BufferedReader fr = new BufferedReader (new FileReader("data.txt"));
String str;
int i=0,j=0,k=0;
int A[][]=new int [3][3], B[][]=new int [3][3];
while((str=fr.readLine()) !=null){
System.out.print("i= "+i+"\t"+str);
k=i/3;
j=i%3;
if(i<9){
A[k][j]=Integer.parseInt(str);
System.out.println("A[" + k + "][" + j + "]= " + A[k][j]+"\t");
i++;
}
else{
k=k-3;
B[k][j]=Integer.parseInt(str);
}
}}}
---
package chap1;
import java.io.*;
public class t0106 {
public static void main(String args[])throws Exception{
BufferedReader fr = new BufferedReader (new FileReader("data.txt"));
String str;
int i=0,j=0,k=0;
int A[][]=new int [3][3], B[][]=new int [3][3];
for(j=0;j<3;j++){
for(i=0;i<3;i++){
A[j][i]=Integer.parseInt(fr.readLine());
System.out.print(A[j][i]+"\t");
}
System.out.println();
}
for(j=0;j<3;j++){
for(i=0;i<3;i++){
B[j][i]=Integer.parseInt(fr.readLine());
System.out.print(B[j][i]+"\t");
}
System.out.println();
}
}
}
----------------------------
資料檔:
9
8
7
6
5
4
3
2
1
11
12
13
21
22
23
31
32
33
--------------小考內容
package chap1;
import java.io.*;
public class t0106 {
public static void main(String args[]) throws Exception {
BufferedReader fr = new BufferedReader(new FileReader("data1.txt"));
String str;
int i = 0, j = 0, k = 0;
int A[][] = new int[3][3], B[][] = new int[3][3], C[][] = new int[3][3];
for (j = 0; j < 3; j++) {
for (i = 0; i < 3; i++) {
A[j][i] = Integer.parseInt(fr.readLine());
System.out.print(A[j][i] + "\t");
}
System.out.println();
}
System.out.println();
for (j = 0; j < 3; j++) {
for (i = 0; i < 3; i++) {
B[j][i] = Integer.parseInt(fr.readLine());
System.out.print(B[j][i] + "\t");
}
System.out.println();
}
System.out.println();
for (k = 0; k < B[0].length; k++) {
for (j = 0; j < A.length; j++) {
for (i = 0; i < A[0].length; i++) {
C[j][k] = C[j][k] + A[j][i] * B[i][k];
}
}
}
for (j = 0; j < A.length; j++) {
for (i = 0; i < A[j].length; i++) {
System.out.print("\t" + A[j][i]);
}
for (i = 0; i < B[j].length; i++) {
System.out.print("\t" + B[j][i]);
}
System.out.print("\t");
for (i = 0; i < C[j].length; i++) {
System.out.print("\t" + C[j][i]);
}
System.out.println();
}
}
}
留言列表