Java Program To Check Armstrong Number

Check Armstrong number

About Armstrong Number

Definition for Armstrong number:

An Armstrong number is a sum of ‘nth’ power of each digit. ‘n’th digit is equal to n digit of a number.
153 = 111 + 555 + 333 — 153 is an Armstrong number
371 = 333 + 777 + 111 — 371 is an Armstrong number

Logic to implemented in program:

  • Get input from keyboard
  • Get total number of digit in given input digit
  • Save input in temp variable for comparison purpose
  • Find the sum of ‘nth’ power of each digit. here n is number of digit in given input number
  • Display the output

1. Check Armstrong number without scanner class

import java.util.Scanner;

public class ArmstrongNo {

	public static void main(String[] args) {
		int inputvalue= 371; // Given number
		
		int temp =  inputvalue, finalresult=0, rem=0,count =0;		
		
		//Get total number of digit of given number
		while(0<inputvalue){			
			inputvalue = inputvalue/10;
			count ++;
		}
		
		//Restore given data to same variable
		inputvalue =  temp;
		
		//Find the sum of 'nth' power of each digit. here 'n' is number of digit in given input number.		
		while(0<inputvalue){
			rem = inputvalue%10;
			inputvalue = inputvalue/10;
			finalresult = finalresult + (int) Math.pow(rem, count);
		}
		
		//Display the output
		if(finalresult==temp){
			System.out.println("Number *"+temp+"* is Armstrong");
		}else{
			System.out.println("Number *"+temp+"* is Not Armstrong");
		}
	}
}
Output:
Number *371* is armstrong

2. Check Armstrong number with scanner class

import java.util.Scanner;

public class ArmtrongNumber {

	public static void main(String[] args) {
		
		
		//Create object for Scanner class to get input digit from keyboard
		Scanner scn = new Scanner(System.in);
		
		//Get input digit from keyboard
		System.out.print("Enter number : ");		
		int inputvalue = scn.nextInt();		
		int temp =  inputvalue, finalresult=0, rem=0,count =0;		
		
		//Get total number of digit of given number
		while(0<inputvalue){			
			inputvalue = inputvalue/10;
			count ++;
		}
		
		//Restore given data to same variable
		inputvalue =  temp;
		
		//Find the sum of 'nth' power of each digit. here 'n' is number of digit in given input number.		
		while(0<inputvalue){
			rem = inputvalue%10;
			inputvalue = inputvalue/10;
			finalresult = finalresult + (int) Math.pow(rem, count);
		}
		
		//Display the output
		if(finalresult==temp){
			System.out.println("Number *"+temp+"* is Amstrong");
		}else{
			System.out.println("Number *"+temp+"* is Not Amstrong");
		}
	}
}
Output 1:
Enter number : 123
Number *123* is Not Amstrong


Output 2:
Enter number : 371
Number *371* is Amstrong

Recommended article:

Hey, Now it is your time! Drop a comment if more details needed or if any update requires. Your comments are more valuable to improve our site to help others.

111 thoughts on “Java Program To Check Armstrong Number”

  1. Fantastic site you have here but I was wanting to know if you knew of any forums that cover the same topics talked about here? I’d really love to be a part of online community where I can get feed-back from other experienced individuals that share the same interest. If you have any recommendations, please let me know. Thanks a lot!

  2. I am really inspired with your writing abilities as smartly as with the layout in your blog.

    Is that this a paid theme or did you modify it your
    self? Either way keep up the nice high quality writing, it is uncommon to
    see a great weblog like this one nowadays..

  3. Thank you for the auspicious writeup. It in fact was a amusement account
    it. Look advanced to far added agreeable from you!

    However, how can we communicate?

  4. of course like your web-site however you need to check the spelling on several of your posts.
    Several of them are rife with spelling issues and
    I find it very troublesome to tell the reality nevertheless I’ll definitely come again again.

  5. Hey! Someone in my Facebook group shared this site
    with us so I came to check it out. I’m definitely loving the information. I’m book-marking and will be tweeting this to my followers!
    Great blog and amazing design.

  6. Hiya! I know this is kinda off topic however , I’d figured I’d ask.

    Would you be interested in trading links or maybe
    guest writing a blog post or vice-versa? My site goes over a
    lot of the same topics as yours and I think we
    could greatly benefit from each other. If you’re interested
    feel free to shoot me an email. I look forward to
    hearing from you! Superb blog by the way!

  7. Thanks for one’s marvelous posting! I really enjoyed reading it, you might
    be a great author. I will ensure that I bookmark your blog and may
    come back down the road. I want to encourage you continue your great work,
    have a nice evening!

  8. Hi there would you mind letting me know which hosting company you’re working with?
    I’ve loaded your blog in 3 completely different web
    browsers and I must say this blog loads a lot faster then most.

    Can you recommend a good hosting provider at a honest price?
    Many thanks, I appreciate it!

  9. Hey there! I’ve been reading your weblog for a long time now and finally got the
    courage to go ahead and give you a shout out from
    Austin Tx! Just wanted to tell you keep up the fantastic job!

  10. I think this is among the most vital info for me. And i’m glad reading your
    article. But wanna remark on some general things,
    The website style is wonderful, the articles is really great : D.
    Good job, cheers

  11. I really like your blog.. very nice colors & theme. Did you make this website yourself or did you hire someone to do it for you?

    Plz respond as I’m looking to design my own blog and would like to find out where
    u got this from. thanks a lot

  12. Hey just wanted to give you a quick heads up and let you know a few of the images aren’t loading correctly.
    I’m not sure why but I think its a linking issue.

    I’ve tried it in two different web browsers and both show the same results.

  13. Howdy! Do you know if they make any plugins to assist with Search Engine Optimization?
    I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good success.
    If you know of any please share. Cheers!

  14. The other day, while I was at work, my sister stole my apple
    ipad and tested to see if it can survive a 40 foot drop,
    just so she can be a youtube sensation. My apple ipad is now destroyed and she has 83 views.
    I know this is completely off topic but I had to share it with someone!

  15. Good day! Do you know if they make any plugins to protect against hackers?

    I’m kinda paranoid about losing everything I’ve worked hard on.
    Any tips?

  16. I was pretty pleased to discover this site. I want
    to to thank you for your time for this particularly wonderful read!!

    I definitely really liked every bit of it and I have you book marked to look at new things on your website.

  17. Hey, I think your site might be having browser compatibility issues.

    When I look at your blog site in Firefox, it looks fine but when opening in Internet
    Explorer, it has some overlapping. I just wanted to give you
    a quick heads up! Other then that, very good blog!

  18. Currently it appears like Drupal is the preferred blogging platform
    out there right now. (from what I’ve read) Is that what you’re using on your blog?

  19. Hi, I do believe this is an excellent website. I stumbledupon it 😉 I’m going to return yet again since I saved as a favorite it.
    Money and freedom is the best way to change, may you be rich
    and continue to help others.

  20. I like the valuable info you supply on your articles.
    I’ll bookmark your blog and check again right here frequently.

    I’m rather sure I will be informed mmany new stuff proper here!
    Best of luck for the next!

  21. Admiring the hard work you put into your site and in depth information you
    present. It’s nice to come across a blog every once in a while that isn’t the same old rehashed information. Excellent read!
    I’ve saved your site and I’m including your RSS feeds to my Google account.

  22. Wow that was strange. I just wrote an really long comment
    but after I clicked submit my comment didn’t show up. Grrrr…
    well I’m not writing all that over again. Anyway, just wanted to
    say excellent blog!

  23. Thank you for any other magnificent article. The place else may anyone get that type of info
    in such an ideal approach of writing? I have a presentation next
    week, and I’m at the search for such info.

  24. You actually make it seem so easy together with your presentation but I to find this matter to be actually something which I think I would never understand.

    It seems too complex and very huge for me. I am having a look
    forward on your next submit, I’ll try to get the hold of it!

  25. I know this if off topic but I’m looking into starting my own weblog and was curious what all is needed to get set up?
    I’m assuming having a blog like yours would cost
    a pretty penny? I’m not very internet smart so I’m not 100% certain. Any recommendations or advice would be greatly
    appreciated. Thank you

  26. This is very interesting, You’re a very professional blogger.
    I have joined your rss feed and stay up for looking for more of your great
    post. Also, I have shared your site in my social networks

  27. I think that is among the most significant info for me. And i’m glad reading your article.
    But should observation on few normal issues, The web site style is wonderful,
    the articles is in point of fact nice : D.
    Excellent task, cheers

  28. Excellent weblog here! Also your web site loads up fast!
    What web host are you the usage of? Can I am getting your associate link on your host?
    I want my site loaded up as quickly as yours lol

  29. Spot on with this write-up, I actually think this amazing site needs
    a lot more attention. I’ll probably be back again to
    read through more, thanks for the info!

  30. I love your blog.. very nice colors & theme. Did you create
    this website yourself or did you hire someone to do it for
    you? Plz answer back as I’m looking to construct my own blog
    and would like to find out where u got this from. thanks
    a lot

  31. It’s a pity you don’t have a donate button! I’d definitely donate to this fantastic blog!
    I suppose for now i’ll settle for bookmarking and adding your
    RSS feed to my Google account. I look forward to new updates and will share this blog
    with my Facebook group. Chat soon!

  32. Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something.
    I think that you can do with some pics to drive the message
    home a bit, but instead of that, this is wonderful blog.
    A fantastic read. I’ll definitely be back.

  33. Heya i’m for the first time here. I came across this board and I find It truly useful & it helped me out a lot.
    I hope to give something back and aid others like you aided
    me.

  34. Hey there this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if
    you have to manually code with HTML. I’m starting a blog soon but have no coding know-how so I wanted to get
    advice from someone with experience. Any help would be enormously
    appreciated!

  35. I was recommended this web site by way of my cousin. I am no longer positive whether
    this put up is written through him as nobody else realize such unique approximately my difficulty.
    You are wonderful! Thank you!

  36. Write more, thats all I have to say. Literally, it seems as though you relied
    on the video to make your point. You obviously know what youre
    talking about, why waste your intelligence on just posting videos to your weblog when you could
    be giving us something informative to read?

  37. Oh my goodness! Amazing article dude! Many thanks, However I am encountering issues with your RSS.

    I don’t understand the reason why I can’t subscribe to it.
    Is there anybody else having the same RSS issues?
    Anybody who knows the answer can you kindly respond? Thanx!!

  38. I’m really enjoying the theme/design of your weblog.
    Do you ever run into any internet browser compatibility issues?
    A number of my blog visitors have complained about my website not working correctly in Explorer but looks great in Chrome.
    Do you have any solutions to help fix this problem?

  39. Hello! I know this is somewhat off-topic however I had to ask.
    Does building a well-established blog such as yours require
    a lot of work? I am completely new to operating a
    blog however I do write in my diary daily.
    I’d like to start a blog so I can easily share my experience and views online.
    Please let me know if you have any kind of ideas or tips for new aspiring blog owners.
    Thankyou!

  40. I do accept as true with all of the ideas you’ve introduced on your post.

    They’re really convincing and will definitely work.
    Nonetheless, the posts are very brief for newbies. Could you please lengthen them
    a little from subsequent time? Thanks for the post.

  41. My spouse and I stumbled over here by a different web page and thought I may as well check things out.
    I like what I see so now i am following you. Look forward to looking at your web page again.

  42. you are actually a excellent webmaster. The web site loading pace is
    amazing. It seems that you’re doing any distinctive
    trick. Moreover, The contents are masterpiece.
    you’ve performed a excellent process in this subject!

  43. Excellent beat ! I wish to apprentice while you amend your website, how could i subscribe
    for a weblog website? The account helped me a appropriate deal.
    I had been tiny bit familiar of this your broadcast provided brilliant
    clear concept

  44. Very nice post. I just stumbled upon your weblog and wished to say that I have truly
    enjoyed browsing your blog posts. After all I’ll be subscribing to your feed
    and I hope you write again soon!

  45. I think this is one of the most important info for me.
    And i am glad reading your article. But should remark on few general things,
    The site style is perfect, the articles is really nice : D.

    Good job, cheers

  46. I am not sure where you’re getting your info,
    but good topic. I needs to spend some time learning
    more or understanding more. Thanks for wonderful information I was looking for this
    information for my mission.

  47. Oh my goodness! Impressive article dude! Thanks,
    However I am encountering problems with your RSS.
    I don’t understand why I am unable to subscribe to it.

    Is there anyone else having identical RSS issues?

    Anyone that knows the solution can you kindly respond?

    Thanks!!

  48. Thanks for one’s marvelous posting! I quite enjoyed reading it, you will be a great author.
    I will always bookmark your blog and will come back sometime soon. I want to encourage
    you to continue your great job, have a nice day!

  49. Finest selling operating watches evaluate, comparison and every part it is advisable leartn about buying a perfect look ahad to running.

  50. It’s the best time to make a few plans for the future and it’s time to be happy.
    I’ve read this put up and if I may just I
    desire to counsel you few fascinating issues or suggestions.
    Maybe you could write subsequent articles referring to this article.
    I wish to learn even more things approximately it!

  51. Pingback: Google

  52. Hello there, I discovered your site by means of Google
    at the same time as looking for a similar topic, your site came up, it seems good.
    I’ve bookmarked it in my google bookmarks.
    Hello there, just turned into alert to your weblog through Google, and found that
    it is really informative. I’m going to watch out for
    brussels. I will be grateful if you proceed this in future.
    A lot of folks can be benefited out of your writing.
    Cheers!

  53. Pingback: Google

  54. Thanks for one’s marvelous posting! I actually
    enjoyed reading it, you can be a great author.I will be sure to
    bookmark your blog and will come back in the future.

    I want to encourage you to continue your great posts, have a nice day!

  55. Excellent post. Keep posting such kind of info on your page.
    Im really impressed by it.
    Hey there, You’ve done an incredible job. I’ll definitely
    digg it and individually suggest to my friends. I’m confident they’ll be benefited from
    this site.

  56. I’m curious to find out what blog system you happen to be using?
    I’m having some small security issues with my latest website and I’d like to find
    something more safe. Do you have any recommendations?

  57. Hmm it looks like your blog ate my first comment (it was extremely long) so I guess I’ll
    just sum it up what I had written and say, I’m thoroughly enjoying your
    blog. I as well am an aspiring blog writer but I’m still
    new to the whole thing. Do you have any tips for inexperienced blog writers?
    I’d certainly appreciate it.

Leave a Comment

Your e-mail address will not be published.