Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.lang.Math;
- public class Aufgabe4 {
- static class CalcThread extends Thread {
- private static Random rand = new Random();
- private static double sum = 0;
- private static int count = 0;
- private int n;
- public CalcThread(int n) {
- this.n = n;
- start(); //starte Thread-Ausfuehrung sofort...
- }
- public void run() {
- //hier kommt Ihr Programmcode...
- //...
- double random[]= new double[n];
- for (int i=0; i<n;i++){
- random[i]=Math.sin(rand.nextDouble());
- sum+=Math.pow(random[i],2);
- count++;
- }
- }
- public static int getCount() {
- return count;
- }
- public static double getSum() {
- return sum;
- }
- }
- public static void main(String[] args) {
- //Kommandozeilenparameter auslesen
- int n = -1;
- if(args.length>=1) {
- n = Integer.valueOf(args[0]);
- } else {
- System.out.println("Erster Parameter fehlt!");
- System.exit(1);
- return;
- }
- //hier kommt Ihr Programmcode...
- //...i have no idea what i am doin
- CalcThread[] threads= new CalcThread[n];
- for(int i=0; i<n;i++){
- //threads[i] new CalcThreads.threads(n);
- threads[i].run();
- //threads[i].join();
- }
- double korrekterDurchschnitt = (0.5 - (0.25 * Math.sin(2)));//...
- double meinDurchschnitt = (CalcThread.getSum()/n);//...
- double abweichung = (100*(meinDurchschnitt - korrekterDurchschnitt)/korrekterDurchschnitt);//...
- System.out.println("Ergebnis: " + meinDurchschnitt + ";" + CalcThread.getCount() + ";" + korrekterDurchschnitt + ";" + abweichung);
- }
- }
Add Comment
Please, Sign In to add comment