Amstrong Number

In case of an Armstrong number of 3 digits, the sum of cubes of each digit is equal to the number itself. For example: 153 = 1*1*1 + 5*5*5 + 3*3*3 // 153 is an Armstrong number.

Program:-

package payilagam.institution;

public class Amstrong {

	public static void main(String[] args) {
		 int num = 370,  temp, total = 0 ;
                 int number=num;
	        
	        while (num > 0)
	        {
	            temp = num % 10;    
	            total = total + temp*temp*temp;  
	            num= num/10;   
	        }
	        System.out.println(total);
	        if(number==total)
	        {
	            System.out.println( "is an Armstrong number");	        }
	        else 
	        {
	            System.out.println( " is not an Armstrong number");	        	

	        }
	}
	
}

Output Screenshot:-

Leave a Reply

Create your own website, free on WordPress.com.Create your own website.
Start free