mercredi 19 août 2015

Failing multiplication

My programm dispalys multiplications of more than 2 components on the console (e.g. 2*3*5=30). The componetns are random numbers. The random numbers are saved in an array and the product of them is calculated b a for loop. The code of this method is

public static RandomNumbers productpro(RandomNumbers a[]){
    int r=1;
    for(int j=0;j<a.length;j++){
        r=r*a[j].get();
    }
    return new RandomNumbers(r);
}

The constuctor of RandomNumbers is

int a=(int) Math.random();
public RandomNumbers(int a){
    this.a=a;
}

This code often not works. This is obviously very annoying and confusing. Thanks for help




Aucun commentaire:

Enregistrer un commentaire