Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //(c)Terminator
- import java.io.*;
- import java.util.*;
- final class ThreadRow extends Thread {
- private float[] row;
- private int index;
- public ThreadRow(float[] _row){
- row = _row;
- this.start();
- }
- @Override
- public void run(){
- index = 0;
- for(int i = 1; i < row.length; ++i){
- if(row[i] > row[index])
- index = i;
- }
- }
- public float Max(){
- return row[index];
- }
- }
- public class MyApp {
- public static void main(String[] args) {
- String fn = "a.txt";
- ThreadRow[] trows = null;
- float[][] mat = null;
- try {
- Scanner scan = new Scanner(new File(fn));
- int rows = scan.nextInt(); // считываем кол-во строк
- int cols = scan.nextInt(); // считывает кол-во столбцов
- trows = new ThreadRow[rows];
- mat = new float[rows][cols];
- // читаем матрицу
- for(int r = 0; r < rows; ++r){
- for(int c = 0; c < cols; ++c)
- mat[r][c] = scan.nextFloat();
- }
- scan.close();
- scan = null;
- // запуск потоков с раздачей по строке матрице
- for(int i = 0; i < trows.length; ++i)
- trows[i] = new ThreadRow(mat[i]);
- // выводим результат работы
- for(int i = 0; i < trows.length; ++i){
- trows[i].join();
- System.out.println("Номер строки №" + i + "\t\tмаксимум: " + trows[i].Max());
- trows[i] = null;
- }
- mat = null;
- trows = null;
- } catch(Exception e){
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement