package demo;
import java.util.Scanner;
public class Demo6{
public static void main(String[] args) {
System.out.println("依次输入老师数量、回车、学生数量、回车、老师数量乘以学生数量个分值");
Scanner sc=new Scanner(System.in);
int tNo=sc.nextInt();
int sNo=sc.nextInt();
int k=tNo*sNo;
int arr[]=new int[k];
for(int n=0;n<k;n++) {
arr[n]=sc.nextInt();
}
for(int n=0;n<k;n++) {
System.out.print(" "+arr[n]);
}
System.out.println();
for(int n=1;n<=tNo;n++) {
Teacher teacher=new Teacher(n,sNo,arr);
teacher.start();
try {
teacher.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class Teacher extends Thread{
int sNo;
int[] arr;
int n;
int sum=0;
int i=0;
static Object o=new Object();
public Teacher(int n,int sNo,int[] arr) {
this.arr=arr;
this.sNo=sNo;
this.n=n;
this.i=(n-1)*sNo;
}
public void run() {
System.out.println(Thread.currentThread().getName()+"起始下标"+i+" "+sum);
for(int j=0;j<sNo;j++) {
sum+=arr[i];
System.out.println(Thread.currentThread().getName()+ ": "+arr[i]);
i++;
}
System.out.println(sum);
}
}