Return second last digit of given number in java

In this topic, we will learn to get the second last digit of a number in Java with the help of examples.
There can be several ways to get second last digit; here we are discussing some solutions.

Using modulo operator

Here, we are using modulo and divide operators to find the second last digit. The modulo operator gives remainder of a number while divide operator gives quotient as a result.

Output

💻 Awesome Tech Resources:
  • Looking for ⚒️ tech jobs? Go to our job portal.
  • Looking for tech events? Go to tech events 🗓️ Calendar.️
2

Using String’s chartAt() method

There is another example in which we can convert the number into a string and then using charAt() method we get second last value after that result convert back to number using Character class.

Output

2

That’s all about how to return second last digit of given number in java.


import_contacts

You may also like:

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.