Computer Science, asked by moazzamfirdous33, 1 year ago

wap to enter a number and check whether it is armstrong or not.

Answers

Answered by lenovoideapadanishka
10

import java.util.*;

class armstrong  

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

int s=0,d,di;

System.out.println("enter a no.");

int n=sc.nextInt();

int x=n;

while(x!=0)

{

d=x%10;

di=d*d*d;

s=s+di;

x=x/10;

}

if(s==n)

System.out.println("armstrong");

else

System.out.println("not armstrong");

}

}

Hope it helps!!!^_^

please mark me as the brainliest!!!!!

Answered by Brenquoler
35

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