answersLogoWhite

0


Best Answer

First, review the definition of an Armstrong, or narcissistic, number:

"...is a number that is the sum of its own digits each raised to the power of the number of digits."

So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:

String numberAsString = "" + number;

Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.

Another way is to get one digit at a time, starting from the right, using the "%" operator.

For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.

First, review the definition of an Armstrong, or narcissistic, number:

"...is a number that is the sum of its own digits each raised to the power of the number of digits."

So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:

String numberAsString = "" + number;

Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.

Another way is to get one digit at a time, starting from the right, using the "%" operator.

For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.

First, review the definition of an Armstrong, or narcissistic, number:

"...is a number that is the sum of its own digits each raised to the power of the number of digits."

So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:

String numberAsString = "" + number;

Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.

Another way is to get one digit at a time, starting from the right, using the "%" operator.

For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.

First, review the definition of an Armstrong, or narcissistic, number:

"...is a number that is the sum of its own digits each raised to the power of the number of digits."

So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:

String numberAsString = "" + number;

Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.

Another way is to get one digit at a time, starting from the right, using the "%" operator.

For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

First, review the definition of an Armstrong, or narcissistic, number:

"...is a number that is the sum of its own digits each raised to the power of the number of digits."

So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:

String numberAsString = "" + number;

Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.

Another way is to get one digit at a time, starting from the right, using the "%" operator.

For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you check whether the given number is Armstrong or not?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

To check whether the given number is an Avogadro number or not?

45


To find Armstrong number in java?

/*Program to find whether given no. is Armstrong or not. Example : Input - 153 Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */ class Armstrong{ public static void main(String args[]){ int num = Integer.parseInt(args[0]); int n = num; //use to check at last time int check=0,remainder; while(num > 0){ remainder = num % 10; check = check + (int)Math.pow(remainder,3); num = num / 10; } if(check == n) System.out.println(n+" is an Armstrong Number"); else System.out.println(n+" is not a Armstrong Number"); } }


Program to check whether the given number is an Armstrong number?

<html> <head> <Script Language="JavaScript"> var a,n,b=0,t; n=parseInt(window.prompt("enter n","0")); t=n; while(n>0) { a=n%10; b=b+a*a*a; n=n/10; } if(b==t) { document.writeln("Armstrong no"); } else { document.writeln("Not an Armstrong no"); } </script> </head> </html>


Write an algorithm to check whether the given number is odd or even?

Type your answer here... i think we should first enter 1 number then check it


Draw a flow chart to check whether a given number is prime or not?

[object Object]


Could you write a assembly language program in tasm To check whether a given number present in a sequence of given memory location containing the string to be checked in 8086?

8086 assembly language program to check wether given number is perfect or not


Write a shell programs for to check whether the given number is an Avogadro number or not?

Avogadro's number is a constant. Therefore only one number is equal to Avogadro's number.


Lab manual in mca 1st sem from ignou?

write a program in C to check whether a given number is apalindrome or not


To check whether the given number is even or odd?

Is the last digit 2, 4, 6, 8 or 0? If yes, it's even, else odd.


To check whether given number is a prime number or not?

See whether the number is divisible by 2, and by all odd numbers up to the square root of the number. For numbers up to 100, it is enough to check the factors 2, 3, 5, and 7. For higher numbers you need to check more factors. For very large numbers (for example, hundreds of digits), more efficient methods are known, but those methods are also more complicated.


How do you draw a Flowchart to find whether the given number is odd or even using counter?

first we write start and then read number and after that check the number is totaly divide by 2 or not if number is totally divide by 2 then number is even else number is odd.


How can you tell whether a given number is a multiple of 2?

If it is even