Showing posts with label list of armstrong number in java. Show all posts
Showing posts with label list of armstrong number in java. Show all posts

Sunday, March 4, 2018

List of Armstrong Number in Java

A very simple program to list down the Armstrong numbers in Java.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.


My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.
 
 
Sample Program Output


Program Listing


public class Main {

    public static void main(String[] args) {
        int a =0;
        int num =0;

        int n, sum, temp, remainder, digits;

        int start = 100;
        int end =2000;

        System.out.println("\n\n");
        System.out.print("List of Armstrong Number in Java");
        System.out.println("\n");

        for (int i = start; i <= end; i++) {

            sum = 0;
            digits = 0;

            temp = i;

            while (temp != 0) {
                digits++;
                temp = temp / 10;
            }

            temp = i;

            while (temp != 0) {
                remainder = temp % 10;
                sum = sum + power(remainder, digits);
                temp = temp / 10;
            }

            if (i == sum)
                System.out.println(i + " is an Armstrong number.");

        }
        System.out.println();
        System.out.print("End of Program");
        System.out.println();
    }

    static int power(int n, int r) {
        int c, p = 1;

        for (c = 1; c <= r; c++)
            p = p * n;

        return p;
    }

    }