public static int lastDigit(int a) {
    if (a >= 0){
    a = a % 10;
    return a;
    }
    else {
    a = a % 10;
    return (a * -1);
    }}

This is my solution. The course hasn't taught if else yet, so I'm wondering if there is a way to do it without the if else.

    public static int lastDigit(int a) {
    a = a % 10;
    return a;

The problem with this is that it will not print the last digit of a negative number as a negative.