Sunday 16 August 2015

WAP in java to check whether the entered no is an Armstrong no or not.

//Armstrong no

import java.util.Scanner;

public class Armstrong {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a no:");

int no=sc.nextInt();
if(no<=0)
System.out.println("Can not determine");
else
{
int s=0,d,n=no;
while(no>0)
{
d=no%10;
s=s+(d*d*d);
no=no/10;
}

if(n==s)
System.out.println("It is an Armstrong no.");
else
System.out.println("It is not an Armstrong no.");
}
}

}

No comments:

Post a Comment