Deficient Number
- Categories Java
Find if number is Deficient Number or not.
Deficient Number: Sum of factors is less than the number itself.
e.g. 21. Factors: 1,3,7 = 11<21.
import java.util.Scanner;
public class DeficientNum
{
public static void main(String[] args)
{
System.out.println("Enter the number:");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int sum = 0;
for(int i = 1; i < n; i++)
{
if (n % i == 0)
sum = sum + i;
}
if (sum < n)
System.out.println("Yes");
else
System.out.println("No");
}
}
You may also like
Single Linked List Programs in Java
28 August, 2021
Implementing Stack using Array in Java
28 August, 2021
Constructor Programs
3 July, 2021