0% found this document useful (0 votes)
8 views2 pages

Note

The document contains a Java program that defines multiple classes implementing the Runnable interface for parallel processing. It includes a class for assigning random values to an array, calculating the sum of the array elements, and placeholders for sorting, finding minimum, and maximum values. The main method initializes an array and starts two threads for random assignment and summation of the array elements.

Uploaded by

Zezo-elganzory
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Note

The document contains a Java program that defines multiple classes implementing the Runnable interface for parallel processing. It includes a class for assigning random values to an array, calculating the sum of the array elements, and placeholders for sorting, finding minimum, and maximum values. The main method initializes an array and starts two threads for random assignment and summation of the array elements.

Uploaded by

Zezo-elganzory
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package com.

company;

import java.util.*;
class parallelAssignment implements Runnable{
double[] x;
parallelAssignment(double[] x){
this.x=x;
}
@Override
public void run() {
Random rd = new Random(); // creating Random object
for (int i = 0; i < this.x.length; i++) {
x[i] = rd.nextInt(100);
System.out.println(x[i]);
}
}
}
class sum implements Runnable{
double[] x;
sum(double[] x){
this.x=x;
}
@Override
public void run() {

double sum=0;
for (int i=0; i<this.x.length ; i++) {
sum = sum + x[i];
}
System.out.print("Sum is"+" "+sum);
}
}
class sort implements Runnable{
@Override
public void run() {

}
}
class min implements Runnable{
@Override
public void run() {

}
}
class max implements Runnable{
@Override
public void run() {

}
}
public class Main {

public static void main(String[] args) {


double arr[] = new double[10];

sum a = new sum(arr);


parallelAssignment r = new parallelAssignment(arr);
Thread t1 = new Thread(r);
Thread t2 = new Thread(a);
synchronized (t1){
t1.start();
t2.start();
}

You might also like