How to check if an integer is in a given range?

前端 未结 18 1369
遥遥无期
遥遥无期 2020-11-27 03:58

Hoping for something more elegant than

if (i>0 && i<100) 
18条回答
  •  失恋的感觉
    2020-11-27 04:34

    If you're looking for something more original than

    if (i > 0 && i < 100)
    

    you can try this

    import static java.lang.Integer.compare;
    ...
    if(compare(i, 0) > compare(i, 100))
    

提交回复
热议问题