Note: A number will be called DISARIUM if sum of its digits powered with their respective position is equal
to the original number.
For example 135 is a DISARIUM
(Workings 1*1+3*2+5*3 = 135, some other DISARIUM are 89, 175, 518 etc) */
import static java.lang.System.out;
class Disarium2
{
static public void main(String...alt)
{
for(int i=1;i<=1000;i++)
{
String s=Integer.toString(i);
int n=i,sum=0,rem=0,l=s.length();
while(n!=0)
{
rem=n%10;
sum+=Math.pow(rem,l);
n/=10;
l--;
}
if(sum==i)
out.println(i);
}
}
}
to the original number.
For example 135 is a DISARIUM
(Workings 1*1+3*2+5*3 = 135, some other DISARIUM are 89, 175, 518 etc) */
import static java.lang.System.out;
class Disarium2
{
static public void main(String...alt)
{
for(int i=1;i<=1000;i++)
{
String s=Integer.toString(i);
int n=i,sum=0,rem=0,l=s.length();
while(n!=0)
{
rem=n%10;
sum+=Math.pow(rem,l);
n/=10;
l--;
}
if(sum==i)
out.println(i);
}
}
}
0 Comment to " Write a Java Program to display all Disarium Number between 1 to 1000."
Post a Comment