Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

how to find armstrong numbers in java

    public static void printArmstrongOrNot(int num) {
        int temp = num;
        int cubeValue = 0;
        while (num != 0) {
            cubeValue += (num % 10) * (num % 10) * (num % 10);
            num /= 10;
        }
        if (cubeValue == temp) {
            System.out.println(temp + " is an armstrong number");
        } else {
            System.out.println(temp + " is not an armstrong number");
        }

    }

    public static void main(String args[]) {
        printArmstrongOrNot(371);
        printArmstrongOrNot(372);
    }
 
PREVIOUS NEXT
Tagged: #find #armstrong #numbers #java
ADD COMMENT
Topic
Name
3+4 =