HowToDoInJava

  • Python
  • Java
  • Spring Boot
  • Dark Mode
Home / Java Examples / Java Program to Check Deficient number

Java Program to Check Deficient number

Learn to write a simple java program to verify if a given number is deficient number or not. The value 2n − σ(n) is called the number’s deficiency.

1. what is a deficient number

The deficient number can be defined as the number for which the sum of the proper divisors is lesser than the number itself.

As an example, consider the number 21. Its proper divisors are 1, 3 and 7, and their sum is 11. Because 11 is less than 21, the number 21 is deficient.

Its deficiency is 2 × 21 − 32 = 10.

Since the aliquot sums of prime numbers equal 1, all prime numbers are deficient. Similarly, all proper divisors of deficient or perfect numbers are deficient.

The first few deficient numbers are:
1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 19, 21, 22, 23, 25, 26, 27, 29, 31, 32, 33 …

2. Java Program to find deficient number

public class Main 
{
	static int divsum(int n) 
	{
		int sum = 0;
		for (int i = 1; i <= (Math.sqrt(n)); i++) {
			if (n % i == 0) {

				if (n / i == i) {
					sum = sum + i;
				} else {
					sum = sum + i;
					sum = sum + (n / i);
				}
			}
		}
		return sum;
	}

	static boolean isDeficientNumber(int n) 
	{
		return (divsum(n) < (2 * n));
	}

	public static void main(String args[]) {
		System.out.println("21 is deficient number : " + isDeficientNumber(21));
		System.out.println("20 is deficient number : " + isDeficientNumber(20));
	}
} 

Program output.

21 is deficient number : true
20 is deficient number : false

Happy Learning !!

Ref : Wikipedia

Was this post helpful?

Let us know if you liked the post. That’s the only way we can improve.
TwitterFacebookLinkedInRedditPocket

About Lokesh Gupta

A family guy with fun loving nature. Love computers, programming and solving everyday problems. Find me on Facebook and Twitter.

Comments are closed on this article!

Search Tutorials

Meta Links

  • About Me
  • Contact Us
  • Privacy policy
  • Advertise
  • Guest and Sponsored Posts

Recommended Reading

  • 10 Life Lessons
  • Secure Hash Algorithms
  • How Web Servers work?
  • How Java I/O Works Internally?
  • Best Way to Learn Java
  • Java Best Practices Guide
  • Microservices Tutorial
  • REST API Tutorial
  • How to Start New Blog

Copyright © 2020 · HowToDoInjava.com · All Rights Reserved. | Sitemap

  • Sealed Classes and Interfaces