Answers for "write a java program that prompts the user for an integer and then prints out all the prime numbers up to that integer?"

3

prime number program in java

// The following method returns a boolean indicating
// if the parameter is a prime number
private boolean isPrimeNaiveIter(int val) {
		if(val == 0 || val == 1)
			return false;
		if(val == 2)
			return true;
        // Look for a divisor other than 1 and val
		for(int div = 2; div*div <= val; div++) {
        	// if found return false
			if(val % div==0)
				return false;
		}
        // No divisors found => return it is a prime number
		return true;
}
Posted by: Guest on March-09-2022

Code answers related to "write a java program that prompts the user for an integer and then prints out all the prime numbers up to that integer?"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language