Java > Logic-1>blueTicket (CodingBat Solution)

Problem:

You have a blue lottery ticket, with ints a, b, and c on it. This makes three pairs, which we'll call ab, bc, and ac. Consider the sum of the numbers in each pair. If any pair sums to exactly 10, the result is 10. Otherwise if the ab sum is exactly 10 more than either bc or ac sums, the result is 5. Otherwise the result is 0.

blueTicket(9, 1, 0) → 10
blueTicket(9, 2, 0) → 0
blueTicket(6, 1, 4) → 10


Solution:

public int blueTicket(int a, int b, int c) {
  if(a+b == 10 || b+c == 10 || a+c == 10)
  return 10;
  else if (a+b == (10 + b+c) ||  a+b == (10 + a+c) )
  return 5;
  else
  return 0;
}


2 comments :

  1. public int blueTicket(int a, int b, int c) {
    int ab = a + b;
    int bc = b + c;
    int ac = a + c;

    if(ab == 10 || bc == 10 || ac == 10){
    return 10;
    }
    if(Math.abs(ab - bc) >= 10 || Math.abs(ab - ac) >= 10){
    return 5;
    }
    return 0;
    }

    ReplyDelete
  2. public int blueTicket(int a, int b, int c) {

    int ab = a+b;
    int ac = a+c;
    int bc = b+c;

    if (ab == 10 ||ac == 10 || bc == 10) return 10;
    if (ab - ac == 10 || ab - bc == 10) return 5;
    return 0;
    }

    ReplyDelete

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