|
|
|
Check Whether Given Number is Armstrong or Not
|
Article:
|
Viewed:
1890
Posted On:
24/07/2013 04:13:48
Hi all,With the help of this article i am going to tell you that how we can check for the number to be armstrong number........
|
|
|
Below is my code:
import
java.util.Scanner; class
armstrongI { public
static void main(String s[]) { int
a,b,c=0,d; System.out.println("enter no. "); Scanner
scan=new Scanner(System.in); a=scan.nextInt(); System.out.println("you
entered ="+a); b=a; while(a!=0) { d=a%10; c=c+d*d*d; a=a/10; } if(c==b) { System.out.println("no
is armtrong"); } else { System.out.println("no.
is not armstrong"); } } }
Step 1: After
writing this in notepad save the file with the name followed by (.java) for eg. I saved it with armstrong.java
Step 2 : Open command prompt
Step 3 : Write javac armstrong.java - Press
Enter for compilation
Step 4
: Write java
armstrong for execution
Output:

Image 1.
|
|
|
|
|
|