1 Star 0 Fork 454

鹏鹏大帅哥/bullshit-codes

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
BuildRange 1.21 KB
一键复制 编辑 原始数据 按行查看 历史
public class BuildRange{
public static void main(String[] args) {
try {
int[] i = buildInt("2,3,4,6");
for(int s: i){
System.out.println(s);
}
float[] f = buildFloat("-200,-60,20,300");
for(float s: f){
System.out.println(s);
}
} catch (Exception e) {
e.printStackTrace();
}
}
/*
* 将字串转为数值分段处理,供它处调用查找目标值所在区间
* 如:"-200,-60,20,300" 转换为 { -∞,-200,-60,20,300,∞ }
* 依类型不同分为int和float两个方法
* 代码删至最简可用
*/
// for Int
public static int[] buildInt(String strInt){
String[] strs = strInt.split(",");
int[] rtnI = new int[strs.length+2];
for(int i=1;i<rtnI.length-1;i++){
rtnI[i] = Integer.parseInt(strs[i-1]);
}
rtnI[0] = Integer.MIN_VALUE;
rtnI[rtnI.length-1] = Integer.MAX_VALUE;
return rtnI;
}
// for Float
public static float[] buildFloat(String strFloat){
String[] strs = strFloat.split(",");
float[] rtnF = new float[strs.length+2];
for(int i=1;i<rtnF.length-1;i++){
rtnF[i] = Float.parseFloat(strs[i-1]);
}
rtnF[0] = Float.MIN_VALUE;
rtnF[rtnF.length-1] = Float.MAX_VALUE;
return rtnF;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/peishuaige/bullshit-codes.git
git@gitee.com:peishuaige/bullshit-codes.git
peishuaige
bullshit-codes
bullshit-codes
master

搜索帮助