Thursday, 11 September 2014

armstrong no in java

package com.swain.cell;

public class Armstrong {
public static void main(String args[])
   {
      int n, sum = 0, temp, r;
      n=407;
      temp = n;

      while( temp != 0 )
      {
         r = temp%10;
         sum = sum + r*r*r;
         temp = temp/10;
      }

      if ( n == sum )
         System.out.println(n+" is an armstrong number.");
      else
         System.out.println(n+" is not an armstrong number.");       
   }

}

No comments:

Post a Comment