Skip to main content
edited body
Source Link
user85459
user85459
public static int lastDigit(int a) {
    a = a % 10;
    if (a <= 0){
    a *= -1;
    }
    return a;
}

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 negativepositive.

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

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.

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

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 positive.

edited tags
Link
user85459
user85459
deleted 38 characters in body
Source Link
user85459
user85459
public static int lastDigit(int a) {
if (a >= 0){
 a = a % 10;
return a;
}
else {
a = if (a %<= 10;0){
return (   a **= -1);1;
    }
    return a;
}

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.

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.

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

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.

added 7 characters in body
Source Link
user85459
user85459
Loading
Source Link
user85459
user85459
Loading