An Armstrong number is the one whose value is equal to the sum of the cubes of its digits. Armstrong Number is a positive number if it is equal to the sum of cubes of its digits is called Armstrong number and if its sum is equal to the number then its a Armstrong number using for if statement. The if statement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular test evaluates to true. The if statement is written with the if keyword, followed by a condition in parentheses, with the code to be executed in between curly brackets. Armstrong Number Program is very popular in java.
public class Armstrong_Numbers { //Write a program to find the armstrong number from 100-999 public static void main(String[] args) { int digit1,digit2,digit3,result,temp; for(int number = 100; number <= 999; number++) { temp = number; digit3=temp%10;//3 temp=temp/10;//12 digit2=temp%10;//2 temp=temp/10;//1 digit1=temp%10;//1 result=(digit1 * digit1 * digit1)+( digit2 * digit2 * digit2)+(digit3 * digit3 * digit3); if(number==result){ System.out.println(number + " is armstrong Number"); } } } }
153 is armstrong Number 370 is armstrong Number 371 is armstrong Number 407 is armstrong NumberTo download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions