Java Program For Finding Armstrong Number

Ram Pothuraju
//File name--> Armstrong.java

import java.io.*;

class Armstrong{
 public static void main(String args[])throws Exception
 {
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  int no,temp,sum=0,rem=0;
 
 
  System.out.println("Enter number:");
  no=temp=Integer.parseInt(br.readLine());
 
  while(no>0)
  {
   rem=no%10;
   sum+=(rem*rem*rem);
   no/=10;
  }
 
  if(sum==temp)
  {
   System.out.println("given number "+temp+" is Armstrong number.");
  }
  else
  {
   System.out.println("given number "+temp+" is not Armstrong number.");
  }
 }


OUTPUT

javac Armstrong.java

java Armstrong
Enter number:
123
given number 123 is not Armstrong number.

java Armstrong
Enter number:
153
given number 153 is Armstrong number.

java Armstrong
Enter number:
307
given number 307 is not Armstrong number.

java Armstrong
Enter number:
370
given number 370 is Armstrong number.
}

Post a Comment

0Comments

Post a Comment (0)