samedi 13 juin 2020

Can anyone spot the error that i am making?

All test case is running successfully except one which is in1To10(9, true) → false. Question:- Given a number n, return true if n is in the range 1..10, inclusive. Unless outsideMode is true, in which case return true if the number is less or equal to 1, or greater or equal to 10.

in1To10(5, false) → true in1To10(11, false) → false in1To10(11, true) → true

My Solution:-

public boolean in1To10(int n, boolean outsideMode) {
  if(n>=1&&n<=10){
    return true;
  }
 else if(outsideMode==true&&(n<=1||n>=10)){
    return true;
  }else
  return false;
}

Aucun commentaire:

Enregistrer un commentaire