Get last digit in a number
There is nothing to explain this code. n%10 returns the remainder when the number is divided by 10. That's it. It is obvious that the multiples of 10 end with 0. So the remainder is the last digit. When you want to get all the digits excluding the last digit, simply replace % with / in the above program.Simple is that.
public static void main(String args)
Scanner s=new Scanner(System.in);
System.out.println("Enter the number");
System.out.println("The last digit is "+n%10);