lundi 22 juin 2020

Return the larger value in the in the given range

While I was practicing on the Coding bat I came across this question which I got stuck at. Given two positive integer values, return the larger value that is in the range of 10...20(inclusive), or return 0 if neither is in that range. max1020(11,19)--> 19

max1020(19,11)--> 19

max1020(11,9)--> 11

Can you help me what went wrong with my solution:-

public int max1020(int a, int b) {
  if((a>=10&&a<=20)||(b>=10&&b<=20)){
    int max;
    if(a>b){
      max=a;
    }else{
      max=b;
    }
    return max;
  }
  return 0;
}

Aucun commentaire:

Enregistrer un commentaire