Author

Author- Ram Ranjeet Kumar

Monday, March 9, 2020

Display how many Armstrong Number Between 1 to 1000 in Java

class ArmstrongNo
{
    public static void main(String[] args)
    {
    int n, temp, d1, d2, d3;   
    System.out.println("Print all Armstrong numbers between 1 and 1000:\n");
    n = 001;
    while (n <= 900)
    {
        d1 = n - ((n / 10) * 10);
        d2 = (n / 10) - ((n / 100) * 10);
        d3 = (n / 100) - ((n / 1000) * 10);
        temp = (d1 * d1 * d1) + (d2 * d2 * d2) + (d3 * d3 * d3);
        if (temp == n)
        {
            System.out.println("\n Armstrong no is: " +temp);
        }
        n++;
    }
    }
}




No comments:

Post a Comment