All pastes #256732 Raw Edit

Visor

public java v1 · immutable
#256732 ·published 2006-11-24 15:57 UTC
rendered paste body
public class TableOfPrimes{  private int[] primes;  TableOfPrimes(int n)  {      primes = new int[n];      int i = 0;      int index = 0;            while(index < primes.length)      {                  if((isPrime(i+1) == true))        {          primes[index] = i + 1;          index++;        }                i++;      }  }    private boolean isPrime(int n)  {      int number = n;      boolean isPrime = false;      int calculation;      if(number == 2)      {        isPrime = true;        return true;      }              for(int i = 2; i < number; i++)      {        calculation = number % i;                if(calculation == 0)        {          isPrime = false;          break;        }        else        {          isPrime = true;        }      }      return isPrime;  }    public void printTable()  {      int index = 1;      int sum = 0;            for(int prime : primes)      {          sum += prime;                    System.out.println("Prime " + index + ": \t" + prime +          "\t - Total: " + sum);                    index++;      }            System.out.println("Total: \t" + sum);  }    public int lookupPrime(int n)  {    return primes[n-1];  }}