Codex

Armstrong

Jul 1st, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1.  /*This program finds whether given no. is Armstrong or not.
  2.  
  3.   Example :
  4.  
  5.            Input - 153
  6.  
  7.            Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */
  8.  
  9. import java.util.Scanner;
  10. class Armstrong
  11. {
  12.  
  13.       public static void main(String args[]){
  14.  
  15.       Scanner sc=new Scanner(System.in);
  16.       int num = sc.nextInt();
  17.  
  18.       int tmp = num; //use to check at last time
  19.  
  20.       int check=0,remainder;
  21.  
  22.       while(num > 0)
  23.       {
  24.  
  25.            remainder = num % 10;
  26.  
  27.            check = check + (int)Math.pow(remainder,3);
  28.  
  29.            num = num / 10;
  30.  
  31.       }
  32.  
  33.       if(check == n)
  34.  
  35.             System.out.println(n+" is an Armstrong Number");
  36.  
  37.       else
  38.  
  39.             System.out.println(n+" is not a Armstrong Number");
  40.  
  41.    }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment