Armstrong Number Program in Java Using If Else

Armstrong number program in java using if else. An armstrong three-digit number is an integer in which the total of its digits’ cubes equals the number itself. Because of the way the number behaves in a specific number base, it is of particular interest to beginning programmers and those learning a new programming language. Armstrong number for beginners to understand the concept of armstrong number from maths and programming for freshers.

Armstrong Number Program in Java Using Pow

pow() is a function that raises a number to the power of another. This function takes two arguments and returns the first parameter’s value multiplied by the second. The value of the first integer raised to the power of the second number is returned by math. pow(double a double b), and you must do the same. To put it another way, you must develop a Java function to calculate the power of integer numbers. Armstrong number in java for freshers.

Pre Increment in Java Program

The value of the first integer raised to the power of the second number is returned by math. pow(double a double b), and you must do the same. To put it another way, you must develop a Java function to calculate the power of integer numbers.

After utilising a variable in an expression, the post increment operator is used to increase its value. The value is used inside the expression and then incremented by one in the post increment. 

The term “pre-increment” refers to the incrementing of a variable before it is evaluated in an expression. The term “post-increment” refers to the incrementing of a variable after it has been evaluated for use in an expression.

While Loop and How to Execute

The while loop in Java is a control flow statement that allows code to be repeated based on a Boolean condition. The while loop is similar to a looping if statement. If the condition evaluates to true, the body of the loop will be executed, and we will proceed to the update expression. armstrong program in java using while loop for freshers. 

The while loop in Java is used to execute a section of code until the provided Boolean condition is true. The loop comes to an end as soon as the Boolean condition is false. The while loop is a type of if statement that repeats itself.

When a statement is true, the while loop executes a specified block of code, and when the statement is false, it ends. The do while loop first performs a piece of code before evaluating a statement to determine if the loop should continue.

class Main 
{
public static void main(String[] args)
{
int low = 999, high = 99999;
for(int number = low + 1; number < high; ++number)
{
int digits = 0;
int result = 0;
int actualnumber = number;
while (actualnumber != 0) 
{
actualnumber /= 10;
++digits;
}
actualnumber = number;
while (actualnumber != 0)
{
int remainder = actualnumber % 10;
result += Math.pow(remainder, digits);
actualnumber /= 10;
}
if (result == number) 
{
System.out.print(number + " ");
}
}
}
}

Output:

1634 8208 9474 54748 92727 93084