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;
}


6 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
  3. Many developers and students also use CodingBat practice problems to prepare for interviews and improve coding confidence through repeated logic-based exercises. Similarly, practical educational tools like GWA Calculator Philippines help students simplify gwacalculatorph academic tasks by providing quick and accurate grade calculations, making study management more organized, efficient, and stress-free.

    ReplyDelete
  4. Similarly, LifeMap Insights is built on the idea that life, like programming, is about making thoughtful decisions and following a clear path toward success. Just as developers use logic to solve coding challenges, LifeMap Insights helps individuals Life Map Insights understand their strengths, identify opportunities, and make intentional decisions that support personal growth.

    ReplyDelete
  5. Calculadora Alicia is a modern online mathematics platform designed to simplify calculations and improve La Calculadora Alicia EspaƱa mathematical understanding for students, teachers, and professionals.

    ReplyDelete
  6. Similarly, Horizon Plus Trading LLC focuses on providing practical solutions for everyday life through a carefully selected range of home essentials, pet accessories, travel products, and lifestyle items. Whether solving coding challenges or improving adopt me pets happy meal daily routines with quality products, smart and reliable solutions help create a more efficient, organized, and enjoyable lifestyle.

    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