Good day. I want to create a program to calculate prime numbers up to an integer limit. I am extremely new to Java ( I'm on hour 13 of Sam's teach yourself Java in 24 hours), so bear with me.
I have established that I must find the factors of a number, then deduce that if the only factors are 1 and the number itself, then i must print that number. After much trial and error, I have given up. My code has changed considerably, and I have added new sections on after every error i received, however now when I run the file, there is simply no output. The requirements for printing the prime number are not being fulfilled, it may be a problem with the loops or the array. Apologies for the messy code.
class Primes { public static void main(String[] args) { // Factors of a number - if the only ones on that list are 1 and the // nunber itself then print it. for (int number = 1; number <= 10; number++) { for (int counter = 1; counter < number; counter++) { int factor = number / counter; int remainder = number % counter; int factorArray[] = new int[10]; if (remainder == 0) { factorArray[counter] = factor; } if (counter == number) { for (int newCounter = 1; newCounter < 10; newCounter++) { int newFactor = 0; newFactor = newFactor + factorArray[newCounter]; if (newCounter == 9) { if (newFactor == (number + 1)) System.out.println(number); } } } } } } }