Skip to main content

Posts

Showing posts with the label Write a java program to check whether a number is Armstrong number or not.

ads1

Write a java program to check whether a number is Armstrong number or not.

  Write a java program to check whether a number is Armstrong number or not.  import java.util.*; class arms {     public static void main(String args[])     {         Scanner in = new Scanner(System.in);         int n,temp,r,sum=0;         System.out.println("Enter any number to check armstrong :-");         n=in.nextInt();         temp=n;         while(temp>0)         {             r=temp%10;             temp = temp/10;             sum = sum+r*r*r;                              }         if(n==sum)         {             System.out.println("It is armstrong");         }         else         {             System.out.println("It is not armstrong :-");         }     } }   Output :-

ads2