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:
- Introduction to java
- How to install java
- Add two matrix multidimensional array in java
- Check given number Prime or Not
- Sort an array in ascending, descending order in java
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.
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!
Thank you
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..
Hi Mindy, Thank you for your comments.
It is not paid theme
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?
Hi there! Do you know if they make any plugins to safeguard against
hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any tips?
Good web site you’ve got here.. It’s hard to find high quality writing like yours nowadays.
I truly appreciate individuals like you! Take care!!
Everything is very open with a very clear explanation of the issues.
It was truly informative. Your website is useful. Thank you for sharing!
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.
It’s very straightforward to find out any matter on net as
compared to textbooks, as I found this post at this web site.
Does your blog have a contact page? I’m having problems locating it but, I’d like to
send you an e-mail. I’ve got some recommendations for your blog
you might be interested in hearing. Either way, great blog and I look forward to seeing it grow over time.
This is a topic which is near to my heart… Best wishes!
Where are your contact details though?
This post is truly a fastidious one it helps new net visitors, who are wishing in favor of blogging.
This website definitely has all of the information I needed about
this subject and didn’t know who to ask.
I am regular visitor, how are you everybody? This article posted at this
site is genuinely fastidious.
My family always say that I am killing my time here at net,
however I know I am getting knowledge everyday by reading such good articles or reviews.
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.
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!
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!
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!
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!
What a information of un-ambiguity and preserveness of valuable familiarity on the topic of unpredicted emotions.
It’s amazing in support of me to have a site, which is beneficial for my know-how.
thanks admin
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
You need to be a part of a contest for one of the greatest blogs on the net.
I am going to recommend this site!
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
Hello, yeah this post is truly pleasant and I have learned lot
of things from it about blogging. thanks.
wonderful post, very informative. I ponder why the other
specialists of this sector do not notice this. You must continue your
writing. I am sure, you’ve a huge readers’ base already!
You could certainly see your skills in the article you write.
The world hopes for even more passionate writers such as you who are not afraid to say
how they believe. At all times follow your heart.
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.
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!
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!
Hello my friend! I wish to say that this post
is awesome, great written and come with almost all significant infos.
I’d like to see extra posts like this .
I savor, lead to I found exactly what I was taking a
look for. You’ve ended my four day lengthy hunt!
God Bless you man. Have a great day. Bye
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?
Thanks to my father who informed me on the topic of this
web site, this weblog is genuinely amazing.
Ahaa, its nice conversation on the topic of this paragraph at this place at this blog,
I have read all that, so now me also commenting at this place.
It’s remarkable in favor of me to have a web site, which is useful for my know-how.
thanks admin
You ought to be a part of a contest for one of the highest quality sites on the web.
I am going to highly recommend this blog!
I always spent my half an hour to read this web site’s articles or reviews
every day along with a mug of coffee.
Hello, its nice article regarding media print, we all be
aware of media is a great source of data.
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.
I couldn’t resist commenting. Well written!
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!
You’ve made some decent points there. I checked on the internet for more information about the issue
and found most individuals will go along with your views on this
site.
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?
It’s amazing for me to have a web page, which is valuable
in support of my experience. thanks admin
If you would like to take a good deal from this piece of writing then you
have to apply such methods to your won webpage.
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.
Fastidious replies in return of this issue with real arguments and telling everything regarding that.
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!
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.
Nice replies in return of this difficulty with firm arguments and describing the whole thing concerning that.
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!
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.
Every weekend i used to go to see this site, because i want enjoyment, as this this site conations really pleasant funny data too.
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!
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
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
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
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
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!
Excellent way of describing, and good post to obtain information on the
topic of my presentation focus, which i am going to convey in college.
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
It’s an awesome piece of writing designed for all the internet visitors; they
will obtain advantage from it I am sure.
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!
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.
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.
Hey there terrific blog! Does running a blog similar to this take
a great deal of work? I’ve very little understanding of programming however I was hoping to start my
own blog soon. Anyways, should you have any recommendations or techniques for new blog owners
please share. I know this is off subject but I just wanted
to ask. Thank you!
Appreciation to my father who informed me on the topic of this
web site, this weblog is really remarkable.
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!
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!
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?
I am sure this paragraph has touched all the internet people, its really really nice
post on building up new blog.
excellent points altogether, you just received a logo new reader.
What might you suggest about your submit that you simply made a few days in the past?
Any sure?
Way cool! Some extremely valid points! I appreciate you penning this write-up plus the rest of the
website is also very good.
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!!
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?
Wow, this article is pleasant, my sister is analyzing these things,
so I am going to inform her.
Appreciate the recommendation. Let me try it out.
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!
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.
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.
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!
I am truly thankful to the owner off this website who has
shared this impressive paragraph at at this time.
I am truly grateful to the owner of this web site who has shared this impressive
piece of writing at here.
Greetings! Very useful advice within this article! It’s the little changes that make the greatest changes.
Thanks for sharing!
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
I go to see day-to-day some blogs and blogs to read articles, except this web site
presents feature based posts.
Wow! This blog looks exactly like my old one! It’s on a entirely different topic
but it has pretty much the same layout and design. Wonderful choice of colors!
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!
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
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.
It’s really very complex in this full of activity life to listen news on TV, so I just use web for that purpose, and obtain the most
up-to-date information.
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!!
I always used to read piece of writing in news papers but now as I am a user of web therefore from now I
am using net for posts, thanks to web.
Amazing! Its really remarkable piece of writing, I have got much clear idea concerning from this piece of
writing.
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!
Finest selling operating watches evaluate, comparison and every part it is advisable leartn about buying a perfect look ahad to running.
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!