Wednesday, February 8, 2017

Java Program to print total Armstrong no between 1 to 100000.

Note: An Armstrong number can calculated as follows.
Step1: Enter a Number[153]
Step2: Count the total digit of number[3]
Step3: Power of each digit to the total no. of digit and sum[(3*3*3)+(5*5*5)+(1*1*1)=153]
Step4: Compare the entered no[153] and getting no[153]. if matched then armstrong no. otherwise no.
*/
import static java.lang.System.out;
import java.io.Console;
class Armstrong2
{
static public void main(String...alt)
{
for(int i=1;i<=100000;i++)
{
String s=Integer.toString(i);
int n=i;
int rem=0,sum=0;
while(n!=0)
{
rem=n%10;
int pow=(int)Math.pow(rem,s.length());
sum=sum+pow;
n=n/10;
}
if(i==sum)
out.println(i);
}
}
}

Share this

0 Comment to "Java Program to print total Armstrong no between 1 to 100000."

Post a Comment