leijuanjuan 2009-12-14 17:24
浏览 129
已采纳

急,求高手解决

1 根据规律写方法

numIncre(“000000”) => “000001”

numIncre(”0023") => “0024”

numIncre(“0009”) => “0010”

numIncre(“000099”) => “000100”

numIncre(“9”) => “0”

public static String numIncre(String num);

2根据规律写方法

round(123.455,2) => 123.46

round(123.449,2) => 123.45

round(123.44,3) => 123.440

round(123.4455,3) => 123.446

round(123.4499,3) => 123.450

round(123.9,0) => 124

public static double strRound(double value,int decimalPlaces);
[b]问题补充:[/b]
我要实现代码

  • 写回答

2条回答 默认 最新

  • weixin_42327899 2009-12-15 10:40
    关注

    import java.math.BigDecimal;

    public class ts_main {

    public static void main(String args[]) {
        System.out.println(numIncre("00019"));
        System.out.println(strRound(123.455,2)) ;
    }
    
    public static String numIncre(String str) {
        return insertStr(getTotal(str), str.length()) + getTotal(str);
    }
    
    public static String insertStr(String _total, int num) {
        String _str = "";
        if (_total.length() < num) {
            for (int i = 0; i < num - _total.length(); i++) {
                _str += "0";
            }
        }
        return _str;
    }
    
    public static String getTotal(String str) {
        return Integer.parseInt(str) + 1 + "";
    }
    
    public static double strRound(double value,int decimalPlaces) {
        if (decimalPlaces < 0){
            throw new IllegalArgumentException(
             "The scale must be a positive integer or zero");
        }
        BigDecimal b = new BigDecimal(Double.toString(value));
        BigDecimal one = new BigDecimal("1");
        return b.divide(one, decimalPlaces, BigDecimal.ROUND_HALF_UP).doubleValue();
    }
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口