Skip to content

Instantly share code, notes, and snippets.

@0ryant
Created August 7, 2019 14:19
Show Gist options
  • Save 0ryant/269211e0aa586608bab8c1d81573ab39 to your computer and use it in GitHub Desktop.
Save 0ryant/269211e0aa586608bab8c1d81573ab39 to your computer and use it in GitHub Desktop.
Java - Coding Challenge - Sum of All Even Digits
public static int getEvenDigitSum(int number){
if (number < 0){
return -1;
}
int sum=0;
for (int i = number; i !=0; i /= 10){
if ((i%10)%2==0){
sum+=i%10;
}
}
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment