Last active
August 7, 2019 14:08
-
-
Save 0ryant/841ac53a46e1392f975dd8e4d7d2e761 to your computer and use it in GitHub Desktop.
Java - Coding Challenge 16 - Sum of First and Last Digit
This file contains hidden or 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){ | |
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