Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given 3 int values, a b c, return their sum. However, if one of the values is th

ID: 3545777 • Letter: G

Question

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


My answer:

public int loneSum(int a, int b, int c) {
}

   int sum;{
    
    // if a, b, c do not = each other
    if( (a != b) && (a != c) && (b != c) )
    {
       sum = a + b + c;
       return sum;
    }
    
    // if a, b, c do = each other
    if( (a == b) && (a == c) && (b == c) )
    {
       return 0;
    }
    
    // if a = c, b /= a or b /= c
    else if( (a != b) && (a == c) && (b != c) )
    {
       sum = a + b;
       return sum;
    }
    
    //if a = b, b /= c or c =/a
    else if( (a == b) && (a != c) && (b != c) )
    {
      sum = b + c;
      return sum;
    }
    
    // if b = c, a /= c and a /= b
    else if( (a != b) && (a != c) && (b == c) )
    {
      sum = a + c;
      return sum;
    }
         
  
}
}



I am getting errors, can anyone please help me?

Explanation / Answer

public int loneSum(int a, int b, int c) {

int sum=0;

if (a==b && a==c)

sum = 0;

else if ((a==b) && c!=a)

sum = c;

else if ((a==c) && b!=c)

sum = b;

else if((b==c) && a!=b)

sum = a;

else

sum = a+b+c;

return sum;


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote