-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
29 lines (28 loc) · 929 Bytes
/
Copy pathtest.java
File metadata and controls
29 lines (28 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package PerfectNumberChecker;
import java.util.Scanner;
/**
* @author Fatih ARI - 20.08.2021
*
* A program is designed to print whether a number is a perfect number or not.
*
* A number whose sum of positive integer factors are equal to itself, excluding the number itself, is called a perfect number.
*
*/
public class test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = input.nextInt();
input.close();
int total = 0;
for (int i = 1; i < number; i++)
{
if(number % i == 0)
total += i;
}
if(total==number)
System.out.println("YES! \"" + number + "\" is a perfect number.\n");
else
System.out.println("NO! \"" + number + "\" is NOT a perfect number.\n");
}
}