我的代码设置为采用数组。
一旦导入数组,
我创建了:
我很难让创建的线程(在我创建的:part。中)立即运行,我不知道可能是什么问题。
import java.util.*;
import java.io.*;
public class ThreadEx{
public static void main(String[] args){
Scanner scanner = new Scanner(new File("rowcolumn.txt"));
int myArray[][] = new int [256][256];
int j = 0;
int k = 0;
while(scanner.hasNextInt()){
myArray[j++][k++] = scanner.nextInt();
}
ShowChar s = new ShowChar();
ShowNum i = new ShowNum();
Thread t1 = new Thread(s);
Thread t2 = new Thread(i);
t1.start(); t2.start();
s.start(); i.start();
}
int row = 0;
int col;
int rowSum = 0;
int colSum = 0;
///////////////////////////////
class ShowChar extends Thread{
for(col = 0; col<5;col++) {
for( row = 0; row<5; row++) {
rowSum = rowSum + myArray[row][col];
}
System.out.println("Sum of row " + rowSum);
rowSum=0;
}
}
class ShowNum extends Thread{
for(row=0; row<10;row++) {
for(col = 0; col<10; col++) {
colSum = colSum + myArray[row][col];
}
System.out.println("Sum of column " + colSum);
colSum=0;
}
}