Then we use math.abs , if entered number is negative.
After that by doing modulus by 10 will give the last digit of given number.
Then print the result.
Java Code to Find the Last Digit of a Number.
import java.util.*;
import java.math.*;
public class LastDigitOfNum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
int y=Math.abs(n);
int ans= y%10;
System.out.println("Last Digit of Number is "+ans);
}
}