Java > Logic-2 >loneSum (CodingBat Solution)

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


Solution:

public int loneSum(int a, int b, int c) {
  if(a ==b && b == c) {
  a=0;b=0;c=0; }
  if (a==b){
  a = 0; b = 0;}
  if (a==c){
  a=0;c=0;}
  if(b==c) {
  b=0;c=0; }

  return a+b+c;
}


No comments :

Post a Comment

Follow Me

If you like our content, feel free to follow me to stay updated.

Subscribe

Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?

Upload

Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact