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

re-publishing

monitor

answered jan 24 "14 in ~ 7:49

RWhitenRWhiten

15366 bronze badges

3

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* …

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

send

### Post together a guest

name

email Required, yet never shown

### Post as a guest

surname

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

related

367

just how to ring up the an outcome of essence division?

302

Why can't decimal number be represented exactly in binary?

36

just how do you publish the specific value that a floating point number?

1220

straightforward interview question gained harder: given numbers 1..100, discover the lacking number(s) given precisely k are absent

1132

how to execute an creature division, and also separately acquire the remainder, in JavaScript?

74

What is the probability that the array will remain the same?

195

how does the HyperLogLog algorithm work?

4

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

assets

firm

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.