Computer Science, asked by traks, 11 months ago

wap in Java to store and Armstrong number​

Answers

Answered by Amartya7
2

Answer:

I hope you meant 'to store a number and find if it is an Armstrong number.'

Explanation:

import java.util.*;

class Armstrong

{

public armstrong()

{

Scanner ag = new Scanner(System.in);

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

int a = ag.nextInt();

int d,s=0,k;

k=a;

while (a!=0)

{

d=d%10;

s=s+(int)Math.pow(d,3);

a=a/10;

}//End of while loop

if (s==k)

System.out.println(k+"is an Armstrong number.");

else

System.out.println(k"is not an Armstrong number.");

}//End of armstrong() method

}//End of Armstrong class

Answered by Brenquoler
1

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