Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Armstrong Numbers Between Two Integers

public class Armstrong {

    public static void main(String[] args) {

        int low = 999, high = 99999;

        for(int number = low + 1; number < high; ++number) {

            if (checkArmstrong(number))
                System.out.print(number + " ");
        }
    }

    public static boolean checkArmstrong(int num) {
        int digits = 0;
        int result = 0;
        int originalNumber = num;

        // number of digits calculation
        while (originalNumber != 0) {
            originalNumber /= 10;
            ++digits;
        }

        originalNumber = num;

        // result contains sum of nth power of its digits
        while (originalNumber != 0) {
            int remainder = originalNumber % 10;
            result += Math.pow(remainder, digits);
            originalNumber /= 10;
        }

        if (result == num)
            return true;

        return false;
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: setsystemuivisibility example 
Java :: equality primitives java 
Java :: what happens if you return only -1 and 1bute not 0 java 
Java :: forge close gui java 
Java :: jadavpur university 
Java :: java feld erstellen 
Java :: if (copy = 5) { in java 
Java :: Java Multiple element Annotations 
Java :: add days to a date java 
Java :: return index using matcher java 
Java :: how to use protobuf in java 
Java :: Copying Arrays Using arraycopy() method Java 
Java :: java :: operator 
Java :: how to set edittext color in android 
Java :: how to use a switch statement in java 
Java :: java arrow function 
Java :: arduino convert byte array to string 
Java :: constructeur java 
Java :: Calling A Class From Another Class In Java 
Java :: how to import borderlayout 
Java :: use of getclass()in string 
Java :: public class extends implements java 
Java :: android MediaStore update cache before query 
Sql :: safe mode off mysql 
Sql :: brew restart mysql 
Sql :: sql disable trigger 
Sql :: wordpress database add admin 
Sql :: display all databases 
Sql :: install mysql ubuntu 18.04 
Sql :: postgres add not null to existing column 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =