Find Last Digit of a Number


  • Take input from user.
  • 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.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);

Last Digit of a Number

Similar Java Tutorials

Leave a Comment