You are here:   HomeJava ProgrammingControl Structures in JavaArmstrong Number With in Range Java Example
by Dinesh Thakur Category: Control Structures

Algorithm for Armstrong Number with in Range:

step 1:Read range

step 2: Set count=0, b= 1

step 3: Repeat through step-11 while b less than or equals to range

step 4: Set sum=0

step 5: Set c=b

step 6: Repeat through step-9 while c greater than 0

step 7: a=c%10

step 8: sum=sum+(a*a*a)

step 9: c=c/10

step 10: if sum equals to b then

print b count=count+1

step 11: b=b+1

step 12: Exit

Here is the Java Example for Armstrong Number with in Range:

import java.util.Scanner;

public class ArmstrongNumberWithinRange
{
               public static void main(String args[])
            {
               Scanner s=new Scanner(System.in);
               System.out.print("Enter the Range :");
               int range=s.nextInt();
               int a,b,c,sum,count=0;
               b=1;
               while(b<=range)
                    {
                        sum=0;
                        c=b;
                        while(c>0)
                             {
                                a=c%10;
                                sum=sum+(a*a*a);
                                c=c/10;
                             }
                         if(sum==b)
                       {
                         System.out.println(b+" is a Armstrong Number");
                         count=count+1;
                       }
                          b++;
                     }
System.out.println("Total Armstrong Number Present With in that Range is "+count);
                }
}

Armstrong Number With in Range Java





Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article