Java > Warmup-1 > makes10 (CodingBat Solution)

Problem:

Given 2 ints, a and b, return true if one if them is 10 or if their sum is 10.

makes10(9, 10) → true
makes10(9, 9) → false
makes10(1, 9) → true


Solution:

public boolean makes10(int a, int b) {
  int sum = a + b;
  if (a == 10 || b == 10)
    return true;
  else if (sum == 10)
    return true;
  else
    return false;
}


1 comment :

  1. public boolean makes10(int a, int b) {
    return a == 10 || b == 10 || a + b == 10;
    }

    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