Saturday, November 23, 2013

Armstrong Number Program Using While Loop


Here is the program to check a number whether it is Armstrong number or not using while loop.

 import java.io.*;
class A
{
int n;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public void take() throws Exception
{
System.out.println("Enter the number:");
n=Integer.parseInt(br.readLine());
if(no(n))
System.out.println(n + " is an armstrong number");
else
System.out.println(n + " is not an armstrong number");
}
private boolean no(int x)
{
int f=0,y,m;
m=x;
while(x>0)
{
y=x%10;
f=f+y*y*y;
x=x/10;
}
if(m==f)
return true;
else
return false;
}
public static void main(String args[]) throws Exception
{
A ob=new A();
ob.take();
}
}

Related PostBlueJ Programs on Number

ICSE and ISC students, please visit this forum site

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner