Java program to find disarium number
This is our complied and working program for disarium number
A number is called Disarium if sum of its digits powered with their respective positions is equal to the number itself.
class Disarium
{
public static void main(String[] args)throws IOException
{
BufferedReader br=newBufferedReader (new InputStreamReader(System.in));
System.out.print("Enter a number : ");
int n = Integer.parseInt(br.readLine());
int copy = n, d = 0, sum = 0;
String s = Integer.toString(n); //converting the number into a String
while(copy>0)
{
d = copy % 10; //extracting the last digit
sum = sum + (int)Math.pow(d,len);
len--;
copy = copy / 10;
}
if(sum == n)
System.out.println(n+" is a Disarium Number.");
else
System.out.println(n+" is not a Disarium Number.");
}
}
Comments
Post a Comment