Let us see, what is perfect number and the code to print perfect numbers in a given range from 1 to n.
What is a Perfect Number?
Perfect Number is a number whose sum of factors is the same number, excluding itself.
Example: 6
factors of 6 are 1, 2, 3 and 6
sum of the factors = 1 + 2 + 3 = 6 (excluding the given number 6).
Java Code to Print Perfect Numbers Between 1 to n
Output:
enter the value for n 50 6 28