0% found this document useful (0 votes)
1 views

Question 4

The document contains a Java program that prints special Armstrong numbers between 500 and 2000. It calculates the sum of the digits raised to the power of the number of digits and checks if this sum equals the original number. If they are equal, the number is printed as an Armstrong number.

Uploaded by

jatincomputer604
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Question 4

The document contains a Java program that prints special Armstrong numbers between 500 and 2000. It calculates the sum of the digits raised to the power of the number of digits and checks if this sum equals the original number. If they are equal, the number is printed as an Armstrong number.

Uploaded by

jatincomputer604
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Question 4: Write a Java program for printing special armstrong number

from 500 to 2000 .( 371=3^3+7^3+1^3=371)

public class special_armstrong

{
public static void main(String args[])
{

for(int i =500 ; i<=2000; ++i )


{
int n =i, num=i , sum=0 ; int count = 0 ; int rem = 0;
while (n >0)
{
n = n / 10;
count ++;
}

while (num>0)
{
rem = num %10;
sum = sum + (int)Math.pow(rem , count );

num = num/10;
}
if (i == sum )
{
System.out.println(i);
}

}
}
}

You might also like