Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
310 views

Armstrong Number (JAVA PROGRAM PDF

JAVA PROGRAM TO CHECK IF A NUMBER IS AN ARMSTRONG NUMBER OR NOT ( An armstrong number is a number in which the sum of cubes of every digit of the number is equal to the number itself. eg. 153 = 1^3 + 5^3 +3^ 3 = 1+125+27 = 153) . WITH COMMENTS AND DETAILS TO HELP YOU UNDERSTAND THEM.THIS PROGRAM HAS BEEN RUN ON BlueJ AND IS ERROR FREE.IT WILL SURELY HELP YOU IN STUDYING JAVA PROGRAMS FOR EXAMS OR OTHERWISE.

Uploaded by

AMRENDRA SINGH
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
310 views

Armstrong Number (JAVA PROGRAM PDF

JAVA PROGRAM TO CHECK IF A NUMBER IS AN ARMSTRONG NUMBER OR NOT ( An armstrong number is a number in which the sum of cubes of every digit of the number is equal to the number itself. eg. 153 = 1^3 + 5^3 +3^ 3 = 1+125+27 = 153) . WITH COMMENTS AND DETAILS TO HELP YOU UNDERSTAND THEM.THIS PROGRAM HAS BEEN RUN ON BlueJ AND IS ERROR FREE.IT WILL SURELY HELP YOU IN STUDYING JAVA PROGRAMS FOR EXAMS OR OTHERWISE.

Uploaded by

AMRENDRA SINGH
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Class armstrong_number 1/1

/*
* ashking13th@gmail.com
* javaprogramsbyashking13th.blogspot.in
* ashkingjava.blogspot.in
*
* QUESTION
*
* Design a program in java to check whether a number
* is an armstrong number or not.
* An armstrong number is a number in which the sum
* ofcubes of every digit of the number is equal to
* the number itself.
* eg. 153 = 1^3 + 5^3 +3^ 3 = 1+125+27 = 153
*/
import java.io.*;
public class armstrong_number
{
public void main()throws IOException
{
DataInputStream d=new DataInputStream(System.in);
System.out.println("enter the number");
int n=Integer.parseInt(d.readLine());
int m=n;
//creating dummy variable
int s=0;
int r=0;
while(m>0)
{
r=m%10;
s=s+(r*r*r);
//finding sum of cubes of digits of the number
m=m/10;
}
if(n==s)
/*
* checking if sum of cubes of every digit if the number
* is equal to the number itself and then displaying messages
* accordingly.
*/
{
System.out.println("Number is an armstrong number");
}
else
{
System.out.println("Number is not an armstrong number");
}
}
}
Mar 25, 2014 3:28:21 PM

You might also like