I am a beginner in Java and I have a task to do, to calculate the sum of prime numbers from the random-generated values of an array.
So, I was told that I should have 3 classes:
1) MyArray - where I have already written this code:
...
public int[] createArray(int n) {
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = rnd.nextInt(10);
}
return a;
}
...
2) IsPrime - where I should do the checking if a number is a prime or not. The problem is I don't know how to 'connect' the array from MyArray to the IsPrime class. I started with a boolean method checkPrime, that has an object m from the MyArray class as a parameter, but I don't know how to continue, how to access the array from the IsPrime class.
I am thankful for any given opinions and advice. Thank you!
P.S. My third class Run.java has the main-method.
Aucun commentaire:
Enregistrer un commentaire