告诉你一个范围假如数字1-10 java中有没有一个方法判断7在不在这个范围中
或者有没有其他好的方法
[code="java"]
public static boolean rangeInDefined(int current, int min, int max)
{
return Math.max(min, current) == Math.min(current, max);
}
public static void main(String[] args) {
int current = 7;
if(rangeInDefined(current, 1, 10))
System.out.println(current + "在1——10之间");
}
[/code]
int max = 10;
int min = 1;
int num = 7;
if(min<num && num<max)
{
……代码段
}
else
{
……
}
直接这样判继不就可以吗?
这种判断就采用简单的判断即可. x >= 1 && x <=10
用java.lang.Math可以做到
int min = 1 ;
int max = 10;
int x = 7 ;
bool isScope = x>=min&&x<=max?true:false;
if(isScope){
.........
}
code="ruby".include? 7
#true
[/code]
楼上这乱入的……那我也来纯凑个热闹,反正前面的人的代码都OK了。
code="ruby" === 7