使用String.format对IP格式化。例如输入"192.168.0.1”,输出"192.168.000.001"。。。。不知道怎么做,谢谢各位大大。。
1条回答 默认 最新
- fang_fumin 2013-02-28 10:27关注
String str = "192.168.0.1";
String[] strs = str.split("\.");
int ip1 = Integer.valueOf(strs[0]).intValue();
int ip2 = Integer.valueOf(strs[1]).intValue();
int ip3 = Integer.valueOf(strs[2]).intValue();
int ip4= Integer.valueOf(strs[3]).intValue();System.out.println(String.format("%1$03d.%2$03d.%3$03d.%4$03d", ip1,ip2,ip3,ip4));
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 神经网络怎么把隐含层变量融合到损失函数中?
- ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
- ¥15 lingo18勾选global solver求解使用的算法
- ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
- ¥15 Python3.5 相关代码写作
- ¥20 测距传感器数据手册i2c
- ¥15 RPA正常跑,cmd输入cookies跑不出来
- ¥15 求帮我调试一下freefem代码
- ¥15 matlab代码解决,怎么运行
- ¥15 R语言Rstudio突然无法启动