Tell me how to pass the fillings of random numbers with the array arr to the stream, to calculate the amount ...
public class ff { public static void main(String[] args) throws InterruptedException { new Threard1().list(); long timer = -System.currentTimeMillis(); Runnable r1 = new Threard1(); Thread t1 = new Thread(r1); t1.start(); t1.join(); System.out.print("\n\n" + "mainSum: " + new Threard1().getSum()); timer += System.currentTimeMillis(); System.out.println("\n" + "Time: " + timer + "\n"); } }
import java.util.Random; public class Threard1 implements Runnable{ private String title = "One"; private int delay=0; private int sizeArr=5; int sum; public int arr[] = new int[sizeArr]; public void list () { Random rand = new Random(); for (int i = 0; i < sizeArr; i++) { arr[i] = rand.nextInt(10); System.out.print("\n" + title + ": " + arr[i]); } } public void run() { for (int i = 0; i < sizeArr; i++) { sum = sum + arr[i]; } try { Thread.sleep(delay); } catch (InterruptedException e) { e.printStackTrace(); } } public int getSum () { return sum; } }