Skip to content

Instantly share code, notes, and snippets.

@0ryant
Last active August 7, 2019 14:08
Show Gist options
  • Save 0ryant/841ac53a46e1392f975dd8e4d7d2e761 to your computer and use it in GitHub Desktop.
Save 0ryant/841ac53a46e1392f975dd8e4d7d2e761 to your computer and use it in GitHub Desktop.
Java - Coding Challenge 16 - Sum of First and Last Digit
public static int sumFirstAndLastDigit(int number){
if (number < 0 ) {
return -1;
}
int firstDigit = number%10;
int lastDigit=0;
for (int i = number; i != 0; i /= 10){
lastDigit = i%10;
}
return firstDigit+lastDigit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment