Aniket_Goku

armstrong no in java

Feb 8th, 2021 (edited)
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class p4
  3. {
  4.  
  5.     public static void main(String args[])
  6.     {
  7.         Scanner s=new Scanner(System.in);
  8.         int i=0,j=0,count,mul=1,sum=0,b=0,a=0;
  9.         System.out.println("ARMSTRONG numbers");
  10.         for(i=10;i<=1000;i++)
  11.         {
  12.             a=i;
  13.             sum=0;
  14.             mul=1;
  15.             b=0;
  16.             count=0;
  17.             while(a!=0)
  18.             {
  19.                 count++;               
  20.                 a=a/10;
  21.             }
  22.             a=i;
  23.             while(a!=0)
  24.             {
  25.                 b=a%10;
  26.                 mul=1;
  27.                 for(j=0;j<count;j++)
  28.                 {
  29.                     mul=mul*b;
  30.                 }
  31.                 sum=sum+mul;
  32.                 a=a/10;
  33.             }  
  34.        
  35.             if(i==sum)
  36.             {
  37.                 System.out.println("=> "+i);
  38.             }
  39.         }      
  40.     }
  41. }
Add Comment
Please, Sign In to add comment