Armstrong Number in Java
Java Programming

Armstrong Number in Java

 

Program to Check Armstrong Number

Armstrong number is that number which is of three  integer digits, which sum of the cube

of its individual digits is equal to that number which we enter like 153, the cube of 1 and the cube of 5,

and the cube of 3 and the sum of both (1*1*1)+(5*5*5)+(3*3*3)=153 means its Armstrong number.

others are…..370,371,407, etc

class arm

{

public static void main(String aa[])

{

int number,sum=0,temp,remainder;

number=Integer.parseInt(aa[0]);  //number enter by user(run time0

temp=number;    //value assign to variable temp

while(temp!=0)    //condition check if temp is not equal 0 then

{

remainder=temp%10;   //show  remainder

sum=sum+remainder*remainder*remainder;  //calculation

temp=temp/10;  

}

if(number==sum)   //if  the value of number and the sum are equal then its armstrong

System.out.print(“armstrong”);

else

System.out.print(“not”);

}}

Armstrong Number in Java

Explanation…

In the above example, we enter the value(integer type). If the value is not equal to zero then the

calculation will start. After calculation, it checks the output if the number and the sum are equal then

the output will Armstrong otherwise not. In this output 153 is the Armstrong number, 255 and 155 are not.

Recommended Posts

C++ Programming

Visibility modes in C++

In C++, visibility modes refer to the accessibility of class members (such as variables and functions) from different parts of a program. C++ provides three visibility modes: public, private, and protected. These modes control the access levels of class members concerning the outside world and derived classes. Public: Members declared as public are accessible from […]

Rekha Setia 
C++ Programming

Inheritance in C++

In C++, inheritance is a fundamental concept of object-oriented programming (OOP) that allows you to create a new class based on an existing class, known as the base or parent class. The new class is called the derived or child class. Inheritance facilitates code reuse and supports the creation of a hierarchy of classes. There […]

Rekha Setia 
C++ Programming

C++ Classes and Objects

In C++, classes and objects are fundamental concepts that support object-oriented programming (OOP). Here’s a brief overview of classes and objects in C++: Classes: In C++, a class is a user-defined data type that allows you to encapsulate data members and member functions into a single unit. Classes are the building blocks of object-oriented programming […]

Rekha Setia 

Leave A Comment