Java program to find Armstrong number using while loop

Java program to find Armstrong number using while loop. In the java programming language, check whether the number is an armstrong number or not. This software will determine whether or not the number is an armstrong number. To print the armstrong number in the output of a java program for beginners.

public class Main
{ 
public static void main(String[] args) 
{ 
int d=0,arm,temp; 
int n=154;
temp=n; 
while(n>0) 
{ 
arm=n%10; 
n=n/10; 
d=d+(arm*arm*arm); 
} 
if(temp==d) 
System.out.println("armstrong number"); 
else 
System.out.println("Not armstrong number"); 
} 
}

 

Output:

154 Not armstrong number

What is while loop and its uses in the armstrong number program

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. The condition is assessed first in a while loop, and if it returns true, the statements inside the while loop are executed.

This process is continued until the condition returns false. When the condition returns false, the control exits the while loop and moves on to the next sentence in the program.

Armstrong number program using temporary variable in java

A temporary variable is a variable in computer programming that has a limited lifetime and is used to retain data that will be deleted shortly or before it can be stored in a more permanent memory location.

It’s generally stated as a local variable, or a variable with a local scope because it’s short-lived. A temporary variable is a variable in computer programming that has a limited lifetime and is used to retain data that will be deleted shortly or before it can be stored in a more permanent memory location. 

It’s generally stated as a local variable, or a variable with a local scope because it’s short-lived.