Computer questions (advanced)-Two super big integers subtraction-using Java class solutions (Java)
The questions are as follows:
The Code is as follows:
Package huawei; import java. math. bigDecimal; public final class Demo {public static void main (String [] args) {String a = "1223424324324317.1234"; String B = "47.1234"; String ans_sub = decrease (, b); System. out. println ("subtraction Result:" + ans_sub );} /*************************************** * ************************************ Description: two positive numbers of any length subtract Input Param: String minuend is reduced. \ 0 indicates that the String ends the String subtrahend, and \ 0 indicates that the String ends. Return Value: subtraction result, ********************************* **************************************** * ***/public static String decrease (String minuend, string subtrahend) {BigDecimal result = null; try {BigDecimal b1 = new BigDecimal (minuend); BigDecimal b2 = new BigDecimal (subtrahend); result = b1.subtract (b2 ). stripTrailingZeros (); // tripTrailingZeros () Remove useless 0} catch (Exception e) {// TODO Auto-generated catch blocke. printStackTrace ();} return (result. toString ();} // remove the first 0}