2.Write a program to check a number is an Armstrong Number or not.Armstrong number: The sum of cubes of each digit is equal to the number itself
Answers
Answer:
Answer:
import java.util.*;
class Armstrong
{
public void main ()
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter a number: ");
int n = sc.nextInt();
int rem,rev = 0;
for(int i = n;i > 0;i/=10)
{
rem = i%10;
rev = rev+rem*rem*rem;
}
if(n == rev)
{
System.out.println("Armstrong Number");
}
else
{
System.out.println("Not Armstrong Number");
}
}
}
I hope you find it useful... If you have any query do comment, I will try to solve it...
Program: {JAVA}
import java.util.*;
public class Brainly
{
static void main()
{
Scanner sc=new Scanner(System.in);
int t,d,s=0,n,f=0;
System.out.println("Enter an integer:");
n=sc.nextInt();
t=n;
while(t!=0)
{
d=t%10;
s=s+d*d*d;
t=t/10;
}
if(s==n)
System.out.println("Armstrong Number");
else
System.out.println("Not an Armstrong Number");
}
}