THIS BLOG IS PROVIDE BIG DATA,JAVA,C++,SQL TUTORIAL
Thursday, 24 May 2018
ARMSTRONG NUMBER PROGRAM IN JAVA
ARMSTRONG NUMBER:
A positive number is calledarmstrong numberif it is equal to the sum of cubes of its digits for example 0, 1, 153, 370, 371, 407 etc.153 = (1*1*1)+(5*5*5)+(3*3*3) =153 The sum of square of given number is equal to that number then number is armstrong otherwise number is not armstrong.
LETS UNDERSTAND 153 IS ARMSTRONG NUMBER OR NOT
153=(1*1*1)+(5*5*5)+(3*3*3)
(1*1*1)=1
(5*5*5)=125 (
3*3*3)=27
So: 1+125+27=153(VALUE IS SAME THEN THE NUMBER IS ARMSTRONG)
371 = (3*3*3)+(7*7*7)+(1*1*1)
where: (3*3*3)=27 (7*7*7)=343 (1*1*1)=1 So: 27+343+1=371
PROGRAM TO CHECK WHETHER THE GIVEN NUMBER IS ARMSTRONG OR NOT:
import java.util.*;
Armstrong{
publicstaticvoid main(String[] args) {
int c=0,a,temp;
System.out.println("enter the number to check number is armstrong");
No comments:
Post a Comment