Last active
October 25, 2022 04:04
-
-
Save ilialloyd/8cb1fbaf86d3d1e62c7847e88bf49143 to your computer and use it in GitHub Desktop.
First And Last Digit Sum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int sumFirstAndLastDigit(int number) { | |
int lastDigit; | |
int sum = 0; | |
if(number<0){ | |
return -1; | |
} | |
lastDigit = number % 10; | |
while (number > 9) {//this will give us last digit | |
number = number / 10; | |
} | |
sum = lastDigit + number; | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment