Write a java program to input a number. Use a function intArmstrong(int n) to receive the number and check whether it is an Armstrong number or not. The function returns 1 if the number is Armstrong otherwise returns 0
Answers
Answered by
4
28
import java.util.Scanner;
class ArmstrongRecursion
{
int x;
int findArmstrong(int n,int a)
{
if(n!=0)
{
x=n%10;
a=a+(x*x*x);
n/=10 ;
return findArmstrong(n,a);
}
return a;
}
public static void main(String[] arg)
{
ArmstrongRecursion A=new ArmstrongRecursion();
int arm;
System.out.println("Armstrong numbers between 1 to 1000");
for(int num=1;num<500;num++)
{
arm=A.findArmstrong(num,0);
if(arm==num)
System.out.println(num);
}
}
}
Similar questions
Hindi,
6 months ago
Social Sciences,
1 year ago
Environmental Sciences,
1 year ago
English,
1 year ago