7-149 多线程计算 (20 分)

7-149 多线程计算 (20 分)
已知某学校有n名教师,学校有m名学生,学校搞学生民意调查,每一位学生为每一位老师都打分,学生所打的所有的分数都集中到一个数组中。数据存放规律是,前m个数据是对1号老师的打分,接下来m个数据是对2号老师的打分,以此类推。请设计一个多线程的算法,计算出每一位老师的总打分。

输入格式:
第一行输入教师数,第二行输入学生数,第三行输入所有n*m个打分(整型),各个分数之间以一个空格分隔

输出格式:
按照教师原来的顺序,每行输出每一位老师的得分

输入样例:
在这里给出一组输入。例如:

2
3
1 2 3 4 5 6
结尾无空行
输出样例:
在这里给出相应的输出。例如:

6
15
结尾无空行

在这里插入代码片
```import java.util.*;



 public class  Main{
	 
     public static void main(String args[])  {
    	
        Scanner in=new Scanner(System.in);
        int te;
        int stu;
        
        te=in.nextInt();
        stu=in.nextInt();
        teacher tea[]=new teacher[te];
        for(int i=0;i<te;i++)
        {
        	tea[i]=new teacher(stu);
        	for(int j=0;j<stu;j++)
        	{
        		int score=in.nextInt();
        		tea[i].countscore(score);
        	}
        	
        }
        
        
        for(int i=0;i<te;i++)
        {
        	tea[i].start();
        	System.out.println(tea[i].getscore());
        }
        
        
     }
 }
 class teacher extends Thread
 {	
	 int score;
	 int stunum;
	 public teacher(int stunum)
	 {
		 this.stunum=stunum;
	 }
	 public void countscore(int score)
	 {
		 
			 this.score+=score;
		 
	 }
	 public int getscore()
	 {
		 return this.score;
	 }
 }
 

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值