Just return (number % 10)
; i.e. take the modulus. This will be much faster than parsing in and out of a string.
If number
can be negative then use (Math.abs(number) % 10);
More Related Contents:
- Why 2 return statements are mandatory in equals method
- Code after if block inside a for loop doesn’t work
- Does a finally block always get executed in Java?
- How to return multiple objects from a Java method?
- “Missing return statement” within if / for / while
- Returning from a finally block in Java
- Multiple returns: Which one sets the final return value?
- Java: Ternary with no return. (For method calling)
- How to round a number to n decimal places in Java
- Differences between System.out.println() and return in Java
- How to allow introducing only digits in jTextField?
- How to call javascript from Android?
- Return a value from AsyncTask in Android [duplicate]
- Try-catch-finally-return clarification [duplicate]
- Java – why no return type based method overloading?
- Why is return needed even after System.exit(0);
- What does the return keyword do in a void method in Java?
- Try-with-resources and return statements in java
- Can someone explain a void return type in Java?
- Which is best data type for phone number in MySQL and what should Java type mapping for it be?
- Java – Does returning a value break a loop?
- Java interfaces and return types
- Return different type of data from a method in java?
- “Wrong” return type when using if vs. ternary opertator in Java
- Start of week for locale using Joda-Time
- Java: no security manager: RMI class loader disabled
- String variable interpolation Java [duplicate]
- Java data transfer object naming convention?
- What is the reason behind Enum.hashCode()?
- Oracle’s RETURNING INTO usage in Java (JDBC, Prepared Statement)