I'm trying to print the sum of the prime numbers of a given number from the console. I think my test in my while loop might be wrong, but I'm not 100% sure. Any help, I would appreciate. Thanks in advance.
import java.util.*; public class PrimeSum { public static int isPrime(int num) { int sum = 0; int factor = 1; while(factor <= num) { if(num % factor != 0) { sum += factor; factor ++; } else { factor ++; } } return sum; } public static void main(String[] args) { System.out.println("The program gets the sum of all prime numbers."); Scanner scan = new Scanner(System.in); System.out.print("Enter a number: "); int num = scan.nextInt(); int sum = isPrime(num); System.out.println(sum); } }