Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

thanks

how can i write a code in java that gives me last number from any given multipule digit number? thanks

1 Answer

Eric M
Eric M
11,545 Points

Use the modulo operator

your_number % 10

Modulo returns the remainder after division. You'll need to wrap your number in math.abs() first if it can be negative.

I need to print the number in the 'ones' place' how can i get this number, and will it work with 3 digit numbers?

Eric M
Eric M
11,545 Points

Hi Akiva,

If you divide 1582 by 10, what's the remainder? What if you divide 12 by 10, what remains after the division?

It is 2 in both cases. For those numbers I would say that 2 is in the 'ones' place', if you mean something different please let me know.

Cheers,

Eric