Saturday, 3 January 2015

Java program to armstrong number

package com.srk.core;

import java.util.Scanner;

/**
 * @author skummitha
 *
 */
public class Armstrong {
       public static void main(String args[]) {
             int n, sum = 0, r;
             Scanner sc = new Scanner(System.in);
             System.out.println("Enter any integer");
             n = sc.nextInt();
             int n1 = n;
             while (n > 0) {
                    r = n % 10;
                    sum = sum + r * r * r;
                    n = n / 10;
             }
             if (sum == n1)
                    System.out.println("Armstrong");
             else
                    System.out.println("not Armstrong");
       }

}

No comments:

Post a Comment