Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nazmul202101/b7cbc3d1a1df468e98ff8d715620c6e2 to your computer and use it in GitHub Desktop.
Save nazmul202101/b7cbc3d1a1df468e98ff8d715620c6e2 to your computer and use it in GitHub Desktop.
Given 2 positive int values, return the larger value that is in the range 10..20 inclusive, or return 0 if neither is in that range.
//Given 2 positive int values, return the larger value that is in the range 10..20 inclusive, or return 0 if neither is in that range.
//max1020(11, 19) → 19
//max1020(19, 11) → 19
//max1020(11, 9) → 11
public int max1020(int a, int b) {
if(a>=10 || a<=20){
return a;
}
else if(b>=10 || b<=20){
return b;
}
else if(a>b){
return a;
}
else if(b>a){
return b;
}
return 0;
}
@Im-Navi28
Copy link

I think there is some issues with the logic

@OlegKinakh
Copy link

ya thats no good

@OlegKinakh
Copy link

int holda = 0;
int holdb = 0;

if(a>=10 && a<=20){
holda = a;
}else{
holda = 0;
}

if(b>=10 && b<=20){
holdb = b;
}else{
holdb=0;
}

return Math.max(holda,holdb);
}

@brbharath
Copy link

wrong answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment