programming code for armstrong number

package armstrong;
import java.util.Scanner;

public class Armstrong {

    public static void main(String[] args) {
        Scanner value = new Scanner (System.in);
        int a, b=0 ;
        System.out.println("enter the number : ");
        int n=value.nextInt();
        int c=n;
    while(n>0){
              a=n%10;  n=n/10;  b=b+(a*a*a);
              System.out.println(a+"  "+n+"  "+b);  // to see the logic
            }
    if(c==b)  System.out.println("Armstrong number");
    else      System.out.println(" Not Armstrong number");
    }
    }

No comments :

Post a Comment

please be nice here and I will be nice to you..