Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MaxBroj extends Thread {
- private int redniBroj;
- private int[] niz;
- MaxBroj (int[] niz, int rBr) {
- this.redniBroj = rBr;
- this.niz = niz;
- }
- public void run() {
- int max=0;
- for (int i : niz){ // for each petlja (moze i obicna, meni je ova bila cisca)
- if (i > max) max=i;
- }
- System.out.println ("Thread" + redniBroj + " je zavrsio. Max broj u nizu je " + max);
- }
- }
- public class TestNiti {
- public static void main(String args[]) throws InterruptedException {
- // pretpostavimo da je unesena matrica :)
- int[][] matrica = new int[][]{
- {4, 0, 0},
- {1, 5, 1},
- {2, 2, 6}
- };
- // kreiranje threadova, predajemo potrebne podatke:
- // prvi je redak matrice, drugi je broj threada
- MaxBroj mb1 = new MaxBroj(matrica[0], 1);
- MaxBroj mb2 = new MaxBroj(matrica[1], 2);
- MaxBroj mb3 = new MaxBroj(matrica[2], 3);
- mb1.start();
- mb2.start();
- mb3.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement