ok I'm a little mind blown from an assignment i have to do. We have to implement a sequence class from http://ift.tt/25vn9fB (the chapter 10 example) to make a new class called PrimeSequence and it has to right align the first 100 prime sequence numbers. I don't understand the point of implementing the other class and i did it but i know im not following the assignment rules because i dont understand what im supposed to implement from the other class and i also use nothing from the other class. I'm not sure on what i have to do
Sequence Class
public interface Sequence
{
int next();
}
PrimeSequence Class
public class PrimeSequence implements Sequence
{
public PrimeSequence()
{
}
public boolean isPrime(int x)
{
for (int start = 2; start <= Math.sqrt(x); start++)
{
if (x % start == 0)
{
return false;
}
}
return true;
}
public int next()
{
}
}
PrimeSequenceTester
public class PrimeSequenceTester {
public static void main(String[] args)
{
PrimeSequence prime = new PrimeSequence();
int currentNumber = 2;
int primesFound = 0;
while (primesFound < 100) {
if (prime.isPrime(currentNumber))
{
primesFound++;
System.out.printf("%4s",currentNumber + " ");
if (primesFound % 10 == 0)
{
System.out.println();
}
}
currentNumber++;
}
}
Aucun commentaire:
Enregistrer un commentaire