Skip to content

Instantly share code, notes, and snippets.

@ilialloyd
Last active October 25, 2022 04:04
Show Gist options
  • Save ilialloyd/8cb1fbaf86d3d1e62c7847e88bf49143 to your computer and use it in GitHub Desktop.
Save ilialloyd/8cb1fbaf86d3d1e62c7847e88bf49143 to your computer and use it in GitHub Desktop.
First And Last Digit Sum
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