I understand the prize is x%10, however why is the the expression that reveals the rightmost digit?


x % 10 looks like the exactly answer. However is not.

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

-2 % 10 is either -2 or 8 relying on language/implementation/whatever. And neither is actually "last digit".

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


It"s Math

When you use the "%" operator you space asking for "What is the remainder after dividing by that number" so if I have actually 28 % 10 I"m saying "What is the remainder that 28 separated by 10". This, of course, would provide me 8. Gaining the remainder the a number separated by 10 just leaves you v the ones number (right most number).

We use a Decimal / basic 10 number system. For this reason if you usage 10 girlfriend will always get remainders in between 0-9.

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

Summary of operators in Java

improve this price
answered jan 24 "14 in ~ 7:49

15366 bronze title
add a comment |

her Answer

Thanks for contributing solution to ridge Overflow!

Please be sure to answer the question. Administer details and also share her research!

But avoid

Asking because that help, clarification, or responding to various other answers.Making statements based on opinion; ago them up with references or personal experience.

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

See more: What Does Strength Do In Nba 2K17, Attribute Testing

Draft saved
Draft discarded

Sign increase or log in in

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

Post together a guest

email Required, however never shown

Post as a guest


Required, but never shown

write-up Your prize Discard

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

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

The Overflow Blog
Featured on Meta
how to round up the an outcome of integer division?
Why can't decimal numbers be represented exactly in binary?
exactly how do you print the precise value of a floating point number?
straightforward interview question gained harder: provided numbers 1..100, uncover the absent number(s) given exactly k are missing
just how to perform an creature division, and also separately obtain the remainder, in JavaScript?
just how does the HyperLogLog algorithm work?
Why the little bit operation i & (-i) equals to rightmost bit?
just how to ring to nearest also integer?
warm Network questions more hot concerns

concern feed
subscribe to RSS
question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader.


stack Overflow
ridge Exchange Network
site style / logo © 2021 ridge Exchange Inc; user contributions license is granted under cc by-sa. Rev2021.9.21.40254

Stack Overflow works best with JavaScript permitted

her privacy

By click “Accept all cookies”, girlfriend agree ridge Exchange deserve to store cookies on your machine and disclose information in accordance v our Cookie Policy.