I recognize the answer is x%10, yet why is that the expression that reveals the rightthe majority of digit?


*

x % 10 looks choose the correct answer. But is not.

You are watching: Write an expression whose value is the last (rightmost) digit of x

-2 % 10 is either -2 or 8 depending upon language/implementation/whatever before. And neither is actually "last digit".

So the correct answer is abs(x) % 10.


*

It"s Math

When you use the "%" operator you are asking for "What is the remainder after dividing by that number" So if I have 28 % 10 I"m saying "What is the remainder of 28 separated by 10". This, of course, would certainly offer me 8. Getting the remainder of a number divided by 10 only leaves you through the ones digit (appropriate a lot of number).

We usage a Decimal / Base 10 number mechanism. So if you usage 10 you will always gain remainders in between 0-9.

In Java, "%" is the remainder operator and also functions the method explained over.

Outline of Operators in Java


Share
Follow
answered Jan 24 "14 at 7:49
*

RWhitenRWhiten
15366 bronze badges
3
Add a comment |

Your Answer


Thanks for contributing a solution to Stack Overflow!

Please be certain to answer the question. Provide details and also share your research!

But avoid

Asking for assist, clarification, or responding to various other answers.Making statements based upon opinion; ago them up via references or individual experience.

To learn even more, view our tips on creating excellent answers.

See more: Find An Equation Of The Plane. The Plane Through The Points, Linear Algebra


Draft saved
Draft discarded

Sign up or log in


Sign up using Google
Sign up using Facebook
Sign up making use of Email and Password
Submit

Article as a guest


Name
Email Required, however never before shown


Blog post as a guest


Name
Email

Required, yet never before shown


Post Your Answer Discard

By clicking “Article Your Answer”, you agree to our terms of organization, privacy plan and also cookie policy


Not the answer you're looking for? Browse other inquiries tagged math or ask your very own question.


The Overflow Blog
Featured on Meta
Related
362
How to round up the result of integer division?
300
Why can't decimal numbers be stood for precisely in binary?
36
How do you print the EXACT value of a floating allude number?
1209
Easy intercheck out question acquired harder: given numbers 1..100, discover the absent number(s) offered precisely k are lacking
1114
How to perdevelop an integer department, and independently gain the remainder, in JavaScript?
193
How does the HyperLogLog algorithm work?
2
Why the bit procedure i & (-i) equals to rightthe majority of bit?
47
How to round to nearemainder also integer?
Hot Netjob-related Questions even more warm concerns

Question feed
Subscribe to RSS
Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader.


*

Stack Overflow
Products
Company kind of
Stack Exchange Netoccupational
website style / logo design © 2021 Stack Exreadjust Inc; user contributions licensed under cc by-sa. rev2021.9.20.40247


Stack Overcirculation functions best with JavaScript permitted
*

Your privacy

By clicking “Accept all cookies”, you agree Stack Exreadjust deserve to store cookies on your gadget and also disclose information in accordance through our Cookie Policy.