为了测试数据随手写的代码,希望能帮到您!
import java.math.BigDecimal; public class EnlargeNum { final static Double MAGNIFICATION = 10.0; final static String ORIGIN = "1 赐 2 福 0.3 与 40 你 202.2"; public static void main(String[] args) { StringBuilder tempNumString = new StringBuilder(); StringBuilder newString = new StringBuilder(); for (int i = 0; i < ORIGIN.length(); i++) { if (Character.isDigit(ORIGIN.charAt(i)) || ORIGIN.charAt(i) == '.') { tempNumString.append(ORIGIN.charAt(i)); } else { if (tempNumString.length() != 0) { overNum(tempNumString, newString); } newString.append(ORIGIN.charAt(i)); } } if (tempNumString.length() != 0) { overNum(tempNumString, newString); } System.out.println(newString); } private static void overNum(StringBuilder tempNumString, StringBuilder newString) { double tempNum; tempNum = new BigDecimal(MAGNIFICATION).multiply(new BigDecimal(tempNumString.toString())).doublevalue(); newString.append(tempNum); tempNumString.delete(0, tempNumString.length()); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)