当前位置: 首页 > news >正文

烟台福山建设工程监测网站百度搜索网页版

烟台福山建设工程监测网站,百度搜索网页版,武汉一医院网站建设,推广网站怎么做模板在网上看到一道网试题,手痒痒实现了一下,呵呵。 使用Java多线程实现下述算法: 输入:整数组成的m*n的矩阵A。(m100000, n10000) 输出:一个数列B,数列B中的每一项为矩阵A中对应列数字之和。 1 packagecom…

在网上看到一道网试题,手痒痒实现了一下,呵呵。

使用Java多线程实现下述算法:
   输入:整数组成的m*n的矩阵A。(m=100000, n=10000)
   输出:一个数列B,数列B中的每一项为矩阵A中对应列数字之和。

 

 1 package com.base.multithread;
 2 
 3 import java.io.IOException;
 4 import java.util.ArrayList;
 5 import java.util.List;
 6 import java.util.Scanner;
 7 
 8 public class PrintMatrix {
 9 
10     public static volatile int count = 0;
11 
12     class ComputeRunnable implements Runnable
13     {
14         private int[][] values = null;
15         private int[] results = null;
16         private int colIndex = 0;
17         
18         public void init(int[][] values,int colIndex,int[] results)
19         {
20             this.values = values;
21             this.colIndex = colIndex;
22             this.results = results;
23             
24         }
25 
26         public void run() {
27             int sum = 0;
28             for(int i = 0 ;i < values.length;i++)
29             {
30                 sum = sum + values[i][colIndex];
31             }
32             results[colIndex] = sum;
33             count++;
34         }
35         
36     }
37     /**
38      * @param args
39      * @throws IOException 
40      * @throws InterruptedException 
41      */
42     public static void main(String[] args) throws IOException, InterruptedException {
43         int m = 0;
44         int n = 0;
45         PrintMatrix pm = new PrintMatrix();
46         System.out.print("Print input m(matrix row):");
47         Scanner scanner = new Scanner(System.in);
48         String srow = scanner.nextLine();
49         System.out.print("Print input n(matrix col):");
50         String scol = scanner.nextLine();
51         m = new Integer(srow).intValue();
52         n  = new Integer(scol).intValue();
53         int[][] arrys = new int[m][n];
54         System.out.println("please input " + m +" * " + n +" matrix,each column with space split:");
55         List<String> lines = new ArrayList<String>();
56         int index = 0;
57         while(scanner.hasNextLine())
58         {
59             lines.add(scanner.nextLine());
60             index++;
61             if(index==m)
62                 break;
63         }
64         //未检查输入正确性
65         forint i = 0 ;i < m;i++)
66         {
67             String line = lines.get(i);
68             String[] lineArray = line.split(" ");
69             forint j = 0 ;j < n;j++)
70             {
71                 arrys[i][j] = new Integer(lineArray[j]).intValue();
72             }
73         }
74         int[] results = new int[n];
75         forint i = 0;i < n ;i++)
76         {
77             ComputeRunnable r = pm.new ComputeRunnable();
78             r.init(arrys,i,results);
79             Thread t = new Thread(r);
80             t.start();
81         }
82         while(true)
83         {
84             if(count == n)
85                 break;
86         }
87         for(int i = 0; i < n;i++)
88             System.out.println("|" + results[i] + "|");
89     }
90     
91     
92 }
93 

 

 

转载于:https://www.cnblogs.com/junsky/archive/2010/05/16/1736568.html

http://www.lbrq.cn/news/2635867.html

相关文章:

  • python wordpress api第三方关键词优化排名
  • 青岛外贸建设网站制作常用的网络推广方法
  • 在手机上怎么赚钱博客seo怎么做
  • 如何对网站做压力测试抖音关键词搜索排名收费
  • 做网站都需要准备什么网络推广培训课程内容
  • 如何制作课程网站模板下载微信运营
  • 做动画网站郑州seo优化顾问热狗
  • 网络建设可行性分析怀化网站seo
  • 社交网站设计附近成人电脑培训班
  • 扬州网站建设制作有了域名怎么建网站
  • 武汉微信网站建设站长之家网站流量查询
  • 佛山顺德容桂网站制作关键词网站排名查询
  • 威海专业网站建设营销软文范例大全100
  • 项目经理职责及工作范围搜索引擎优化的方法与技巧
  • 门户网站的定义百度指数使用方法
  • 静态网站做301重定向百度教育网站
  • 做韩国护的网站天津网站建设公司
  • 网站开发会计处理百度一下你就知道搜索引擎
  • 可以做女鞋批发的网站南宁网站seo大概多少钱
  • 郑州做网站七彩科技产品市场调研怎么做
  • 网站联系方式连接怎么做seo薪资水平
  • 怎么做公司销售网站武汉seo排名
  • smarty做网站软文发布网站
  • 网站设计概述广告公司
  • 下载应用商店app玉林网站seo
  • 天津七七一网站建设有限公司怎么样淘宝推广引流方法有哪些
  • 公司网站后台怎么上传视频精准营销
  • 鲜花外贸网站建设百度广告投放
  • 广宏建设集团有限公司网站seo刷排名公司
  • 柬埔寨美女教你用母乳做奶茶原网站seo关键词优化举例
  • 初识排序(下)-- 讲解超详细
  • MQTT与服务器通讯
  • Android 之 面试八股文
  • 【unity实战】使用Unity程序化生成3D随机地牢(附项目源码)
  • Python生产环境部署指南:专业级应用启动方案
  • 当前主流GPU全景讲解:架构、功能与应用方向