Saturday 10 September 2016

loneSum

Goto Problem

Given 3 int values, a b c, return their sum. However, if one of the values is the same as another of the values, it does not count towards the sum.loneSum(1, 2, 3) → 6
loneSum(3, 2, 3) → 2
loneSum(3, 3, 3) → 0

public int loneSum(int a, int b, int c) {
if(a==b) { if(a==c) return 0; else return c; }
if(a==c) { return b; } if(b==c) return a; else return a+b+c; }

No comments:

Post a Comment