我有一个方案来验证网络VLAN范围(1到4094)。输入将采用字符串格式 例如:50-60,65,2345-3010
有人可以建议如何检查输入数字是否在给定范围内?
答案 0 :(得分:0)
int highRange = 4094;
int lowRange =1;
String str = "50-60,65,2345-3010,4000-5100";
String[] comma = str.split(",");
for(int k=highRange; k>lowRange;k--){
for (int i = 0; i < comma.length; i++) {
int ab = comma[i].indexOf("-");
if(ab>0){
String[] value = comma[i].split("-");
for (int j = 0; j < value.length; j++) {
if(k == Integer.parseInt(value[j])){
System.out.println(value[j]);
}
}
}else{
if(k == Integer.parseInt(comma[i])){
System.out.println(comma[i]);
}
}
}
}
output:
4000
3010
2345
65
60
50