Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/purvgwtw/public_html/tutorials/common.php on line 7
Java determine Armstrong Numbers
Sponsered Links
Categories
Sponsered Links

Java determine Armstrong Numbers

Armstrong numbers are the sum of their own digits to the power of the number of digits. For example, if the number is of three digits then armstrong number is a number wholse sum of cubes of its digits is equal to the number itself. Here we are going to determine the armstrong numbers between 1 and 500.

class  ArmstrongNumbers{
    public static void main(String[] args){
        int num, temp, digit1, digit2, digit3;
System.out.println("Armstrong numbers between 1 and 500: ");
num = 1;
while (num <= 1000){
digit1 = num - ((number / 10) * 10);
digit2 = (num / 10) - ((number / 100) * 10);
digit3 = (num / 100) - ((number / 1000) * 10);
temp = (digit1*digit1*digit1) + (digit2*digit2*digit2) + (digit3*digit3*digit3);
if (temp == num){
System.out.println("Armstrong Number:"+ temp);
}
num++;
}
     }
}

Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2014 PURVACOMPUTERS.COM All Right Reserved