Question: ) A prime number is a positive integer divisible only by itself and 1. A number which is not prime is composite. For example, 2,
) A prime number is a positive integer divisible only by itself and 1. A number which is not prime is composite. For example, 2, 3, and 5 are prime, but 4 and 6 are composite. A perfect number, p, is a positive integer that equals the sum of its divisors, excluding p itself. For example, 6 is a perfect number because the divisors of 6 (1, 2, and 3) add up to 6. Write a program which looks for primes and perfect numbers as follows. Prompt the user to enter the minimum value to check, and ensure that the user enters an integer greater than 1. Next, prompt the user to enter the maximum value to check, and ensure that the user enters an integer greater than the minimum value he/she just entered. For each integer x between the minimum and maximum values to check (inclusive), print a list of all the divisors of x starting from 1 up to x-1. Then print whether x is prime or composite. Next, print whether x is perfect or not perfect. Finally, print a count of the number of primes found and a count of the number of perfect numbers found. Here is the output from an example run of the program: Let's search for prime numbers and perfect numbers! Enter minimum value to check (an integer greater than 1): 0 That entry was not valid. Please be sure to enter an integer greater than 1. Enter minimum value to check (an integer greater than 1): 1 That entry was not valid. Please be sure to enter an integer greater than 1. Enter minimum value to check (an integer greater than 1): 2 Enter maximum value to check (an integer greater than the minimum value to check): 1 That entry was not valid. Please be sure to enter an integer greater than the minimum value to check. Enter maximum value to check (an integer greater than the minimum value to check): 2 That entry was not valid. Please be sure to enter an integer greater than the minimum value to check. Enter maximum value to check (an integer greater than the minimum value to check): 6 2 is divisible by: 1 2 is prime. 2 is not perfect. 3 is divisible by: 1 3 is prime. 3 is not perfect. 4 is divisible by: 1 2 4 is composite. 4 is not perfect. 5 is divisible by: 1 5 is prime. 5 is not perfect. 6 is divisible by: 1 2 3 6 is composite. 6 is perfect. Primes found: 3 Perfect numbers found: 1 [JAVA]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
