Armstrong number program in java

Java code to check give number is Armstrong number or not

import java.io.*;

class Test {
     public static void main(String[] args) throws IOException {

          int num,r,sum=0,temp;
          System.out.println("Enter a number:-");
          BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
          num=Integer.parseInt(br.readLine());
          System.out.println("Enter a number:-"+num);

          temp=num;

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

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

     }
}

No comments: