Computer Science, asked by sonu1592, 1 year ago

checking armstrong number in java using function

Answers

Answered by Jades23
3
Answer is in pic......
hope it is helpful
Attachments:

sonu1592: do it in function
Jades23: Ya that is what i have done
Jades23: bunty is the function name.
sonu1592: ok ok i understood thanks for your answer
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