I have my code and it compiles, and makes sense to me, but I must have something wrong because it only puts out 0's on everything except 1. There is something I am missing, and I don't see it yet.
import java.util.Scanner;
public class MyBestFreon
{
static int max;
static Scanner input = new Scanner(System.in);
static int reps = 0;
static boolean prime = true;
public static void main(String[] args)
{
System.out.print("What would you like the upperbound to be? ===> ");
max = input.nextInt();
System.out.println();
System.out.println();
int primes[] = new int[max];
reps = computePrimes(primes);
displayPrimes(primes, reps);
}
public static int computePrimes(int primes[])
{
for(int n=1; n<=max; n++)
{
for(int i=2; i<max/2; i++)
{
if(n%i==0)
{
prime = false;
}
reps++;
}
if(prime)
{
primes[n] = n;
}
}
return reps;
}
public static int displayPrimes(int primes[], int reps)
{
for(int i=0; i<max; i++)
{
System.out.print(primes[i] + " ");
}
System.out.println();
System.out.println();
System.out.println("The program had to loop " + reps + " times.");
return reps;
}
}