Computer Science, asked by iamwbcgamer236, 22 days ago

Write a program to enter a number and check whether the number is an Armstrong
Number or not.​

Answers

Answered by amansarrafas24payxgs
3

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...

Answered by TheUntrustworthy
9

An Armstrong number is a number whose sum of cubes of digits is equal to the number itself.

For example:

153 = 1³+5³+3³

1+125+27

=153

Program:

import java. util.*;

class Armstrong

{

public static void main (string args [])

{

Scanner sc = new Scanner

int n, r, p, s=0, m;

System.out.println ("Enter a number");

n=sc.nextInt();

while

{

r=n%10

p=r*r*r;

s=s+p;

n=n/10;

}

if (m==s)

System.out.println (m+"is Armstrong");

else

System.out.println (m+"is not Armstrong");

}

}

Similar questions