×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Harshad Number or Niven Number Twin Prime
Disarium Number - Java
10306    Arnab De    11/12/2018

Write a Program in Java to input a number and check whether it is a Disarium Number or not.

DISARIUM Number : Sum of the digits of a number powered by its own position in the number, generate a number. If this generated number equal to the original number then its known as Disarium Number.
For example 135 is a DISARIUM (Workings 11+32+53 = 135, some other DISARIUM are 89, 175, 518 etc). At first read the number from the user, now convert it into string and find out the length or total no of digits of the number. now get the digits one by one and powered by the length from the back and stored in a variable. Now compare the variable with the original number. if it is equal then print a positive message otherwise print a negative message.

softetechnologies
import java.util.*;
class Disarium
{
	public static void main(String []args)
	{
		Scanner sc=new Scanner(System.in);
        	System.out.print("Enter a Number : ");
        	int no=sc.nextInt();
        	int s=0,n=no,l=String.valueOf(no).length();
		while(n>0)
		{
			s += Math.pow(n%10,l);
			n /= 10;
			l--;
		}
		if(no==s)
		{
			System.out.print(no + " is a Disarium Number");
		}
		else
		{
			System.out.print(no + " is not a Disarium Number");			
		}
	}
}
softetechnologies
Harshad Number or Niven Number Twin Prime
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Sri Sri Ramakrishna Paramahamsa
If you want to go east, don't go west.
Sri Sri Ramakrishna Paramahamsa
1061
60.61
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     44721
01/01/2018     36882
25/06/2018     36855
28/06/2017     34896
02/08/2017     33492
01/08/2017     27840
06/07/2017     27613
15/05/2017     27180
14/07/2017     22943
11/09/2018     21679
softetechnologies