【问题标题】:Split a Integer every 3rd position and make operations with those numbers?每第三个位置拆分一个整数并使用这些数字进行操作?
【发布时间】:2013-03-07 19:49:20
【问题描述】:

例如。 我有Integer=45859694,我需要这样从左到右拆分 458,596,94 并将第一个数字乘以 7,第二个数字乘以 3,第三个数字乘以 1

【问题讨论】:

  • 听起来像是功课..whathaveyoutried.com
  • 我需要生成银行参考,他们只是给出步骤

标签: java algorithm split integer sum


【解决方案1】:
String value =Integer.toString();
String tempVal;
int index = 0;
while (index<value.size()){
    if (index+3>value.size(){
       tempVal = value.substring(index);
       //do my operation on Integer.parseInt(tempVal)
       break;
    }
    tempVal = value.substring(index,index+3);
    //do my operation on Integer.parseInt(tempVal)
    index +=3;
}

如果不是整数对象,则为 String.valueof

【讨论】:

  • 哈哈被接受了,我什至没有输入正确,很好地编辑它以适合真实答案
【解决方案2】:

获取整数的字符串表示(String.valueOf),然后转换为数组,处理数组中三个元素的组。 你到家了!

【讨论】:

    猜你喜欢
    • 2016-11-07
    • 2012-07-06
    • 1970-01-01
    • 2012-09-23
    • 2011-05-07
    • 2021-06-22
    • 2019-12-04
    • 1970-01-01
    • 2020-02-09
    相关资源
    最近更新 更多