Java > Logic-1 > inOrder (CodingBat Solution)

Problem:

Given three ints, a b c, return true if b is greater than a, and c is greater than b. However, with the exception that if "bOk" is true, b does not need to be greater than a.

inOrder(1, 2, 4, false) → true
inOrder(1, 2, 1, false) → false
inOrder(1, 1, 2, true) → true


Solution:

public boolean inOrder(int a, int b, int c, boolean bOk) {
  if(bOk) {
    if (c > b)
      return true;
    else
      return false;
  }
  if (b > a && c > b)
    return true;
  else
    return false;
}


8 comments :

  1. if (bOk){
    return (b<c);
    }
    return (a<b && b<c);

    Shorter...

    ReplyDelete
  2. return (bOk) ? (b<c) : (a<b && b<c);

    ReplyDelete
  3. if (bOk)
    return (c > b);

    return (b > a && c > b);

    ReplyDelete
  4. i was analyzing a number of your content material harshly this website and that i conceive this net web page is in reality informative ! hold whilst inspiration to setting happening. Young Thug Net Worth

    ReplyDelete
  5. return ((!equalOk)? (a<b && b<c) : (a<=b && b<=c));

    ReplyDelete
  6. public boolean inOrder(int a, int b, int c, boolean bOk) {
    return (bOk || a < b) && (b < c);
    }

    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