DWQA Ask QuestionCategory: JavaJava_Q: Program to Check if a number is Armstrong number
admin Staff asked 5 years ago

Program to Check if a number is Armstrong number

2 Answers
Ankita Rawat answered 5 years ago

public class Fibonacci {

public static void main(String[] args) {
int n;

Scanner scan=new Scanner(System.in);
System.out.println(“Enter any positive number :”);
n=scan.nextInt();

int a = -1;
int b= 1;
int c=0;

c= a + b;
System.out.println(“The Fibonacci series are :”);
while(c<=n)
{
int temp=a;
a=b;
b=c;
System.out.println(c);
c= a + b;

}
}
}

Kulkarni Arundhati answered 5 years ago

 

Start your code here
public class Armstrong {

public static void main(String[] args) {
// TODO Auto-generated met
int c=0,a,temp;
int n=4;//It is the number to check armstrong
temp=n;
while(n>0)
{
a=n%10;
n=n/10;
c=c+(a*a*a);
}
if(temp==c)
System.out.println("armstrong number" + temp);
else
System.out.println("Not armstrong number" + temp);
}


}