I know the price is x%10, but why is that the expression the reveals the rightmost digit?


x % 10 looks like 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. And also neither is in reality "last digit".

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


It"s Math

When you usage the "%" operator you are asking because that "What is the remainder after splitting by that number" for this reason if I have 28 % 10 I"m speak "What is the remainder of 28 divided by 10". This, that course, would give me 8. Gaining the remainder the a number divided by 10 just leaves you with the ones number (right many number).

We use a Decimal / basic 10 number system. So if you usage 10 friend will constantly get remainders in between 0-9.

In Java, "%" is the remainder operator and also works the method described above.

Summary of operator in Java

answered jan 24 "14 in ~ 7:49

15366 bronze badges
add a comment |

her Answer

Thanks because that contributing response to stack Overflow!

Please be sure to answer the question. Carry out details and share your research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them increase with references or an individual experience.

To learn more, watch our tips on writing good answers.

See more: Ebooks Download Pharmacotherapy A Pathophysiologic Approach 10Th Edition Pdf

Draft saved
Draft discarded

Sign increase or log in

authorize up making use of Google
authorize up utilizing Facebook
authorize up using Email and Password

Post together a guest

email Required, yet never shown

Post as a guest


Required, but never shown

write-up Your price Discard

By clicking “Post her Answer”, friend agree to our regards to service, privacy policy and cookie policy

Not the prize you're looking for? Browse various other questions tagged math or ask your very own question.

The Overflow Blog
Featured ~ above Meta
just how to ring up the an outcome of essence division?
Why can't decimal number be represented exactly in binary?
just how do you publish the specific value that a floating point number?
straightforward interview question gained harder: given numbers 1..100, discover the lacking number(s) given precisely k are absent
how to execute an creature division, and also separately acquire the remainder, in JavaScript?
What is the probability that the array will remain the same?
how does the HyperLogLog algorithm work?
Why the bit operation ns & (-i) equals to rightmost bit?
hot Network concerns an ext hot concerns

concern feed
i ordered it to RSS
inquiry feed To subscribe to this RSS feed, copy and also paste this URL right into your RSS reader.


stack Overflow
ridge Exchange Network
site design / logo design © 2021 ridge Exchange Inc; user contributions licensed under cc by-sa. Rev2021.11.23.40817

Stack Overflow works ideal with JavaScript permitted

your privacy

By click “Accept every cookies”, girlfriend agree stack Exchange deserve to store cookie on your machine and disclose details in accordance with our Cookie Policy.