Computer Science, asked by Titan172004, 2 months ago

(b)
The following is a function of some class which checks if a positive integer is an
Armstrong number by returning true or false. (A number is said to be Armstrong if
the sum of the cubes of all its digits is equal to the original number.)The function
does not use modulus (%) operator to extract digit. There are some places in the
code marked by ?1?, ?2?, ?3?, ?4?, ?5?which may be replaced by a
statement/expression so that the function works properly.
boolean ArmstrongNum( int N)
int sum= ?1?;
int num=N;
while( num>0)
int f= num/10;
int s = ?2?;
int digit = num-s;
sum+= ?3?;
num = ?4?;
}
if(?5?)
return true;
else
return false;

Answers

Answered by sahunix
0

/*to check and display whether a number is Armstrong number or not*/

import java.util.*;

class Armstrong

{

   public static void main(String args[ ])

   {

       Scanner sc = new Scanner(System.in);

       int n,a,num,s=0;

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

       n = sc.nextInt();

       num = n;

       while(n>0)

       {

           a = n%10;

           s = s+a*a*a;

           n = n/10;

       }

       if (num==s)

           System.out.println("Armstrong number");

       else

           System.out.println("Not Armstrong number");

   }

}

Similar questions