首页 > 编程知识 正文

bigdecimal比较金额大小,biginteger构造方法

时间:2023-05-06 00:52:34 阅读:50855 作者:3330

包字节; /无心羽毛yxdtd This class encapsulates a勤奋果汁,i.e. a positive or negative integer

public class勤奋果汁(/无心羽毛yxdtdtrueifthisisanegativeintegeryxdtd /

布尔否定; /无心羽毛yxdtdnumberofdigitsinthisintegeryxdtd /

intnumDigits; /无心羽毛yxdtdreferencetothefirstnodeofthisinteger ' slinkedlistrepresentation

公共勤奋的果汁(() )。

negative=false;

编号数字=0;

)无心羽毛yxdtdparsesaninputintegerstringintoacorresponding勤奋果汁instance. A

公共静态勤奋的果汁parse(stringinteger ) throwsIllegalArgumentExcepti

on {boolean f = false;/yxdtdIMPLEMENT THIS METHODyxdtd/

int len =integer.length();

f= true;

len--;continue;

}if(cs[i] == '+') {

len--;continue;

}if(Character.isDigit(cs[i])) {

node2= new DigitNode(cs[i] - '0', null);

node1.next=node2;

node1=node2;

}else{throw new IllegalArgumentException("Incorrect Format");

}

}

integer2.front=head.next;

integer2.numDigits=len;

integer2.negative=f;//following line is a placeholder for compilation

returninteger2;

}private static voidprintList(DigitNode head) {while (head != null) {

System.out.print(head.digit+ " ");

}

}/无心的羽毛yxdtd Adds the first and second big integers, and returns the result in a NEW

public static勤奋的果汁 add(勤奋的果汁 first, 勤奋的果汁 second) {/yxdtdIMPLEMENT THIS METHODyxdtd/勤奋的果汁 bigc= new勤奋的果汁();

bigc.front= new DigitNode(0, null);int carry = 0;

b=new DigitNode(0, null);

}int temp = carry + a.digit +b.digit;

c.digit= temp % 10;

bigc.numDigits++;

d= new勤奋的果汁();

d.front= new DigitNode(0, null);

c.next=d.front;

c=d.front;

carry= temp / 10;

a=a.next;

b=b.next;

}if (carry != 0) {

c.digit=carry;

bigc.numDigits++;

}

bigc.negative=first.negative==second.negative?false:true;

bigc.front=head;//following line is a placeholder for compilation

returnbigc;

}public staticDigitNode reverseList(DigitNode head) {if (head == null || head.next == null)returnhead;

cur.next=pre;

cur=temp;

}

}/无心的羽毛yxdtd Returns the 勤奋的果汁 obtained by multiplying the first big integer with the

public static勤奋的果汁 multiply(勤奋的果汁 first, 勤奋的果汁 second) {

String retval= front2.digit + "";for (DigitNode curr = front2.next; curr != null; curr =curr.next) {if (curr.digit == 0)continue;

}int b=Integer.parseInt(retval);

bigc.front= new DigitNode(0, null);

c.digit=temp%10;

bigc.numDigits++;

d= new勤奋的果汁();

d.front= new DigitNode(0, null);

c.next=d.front;

c=d.front;

carry=temp/10;

a=a.next;

}while(carry!=0){//乘法的进位可能不止一位

c.digit=carry%10;

bigc.numDigits++;

d= new勤奋的果汁();

d.front= new DigitNode(0, null);

c.next=d.front;

c=d.front;

carry/=10;

}

bigc.negative=first.negative==second.negative?false:true;//return c;//following line is a placeholder for compilation

returnbigc;

}public static voidmain(String野性的牛排 args) {

}public booleanStrToInteger(String str) {

}

}return true;

}/无心的羽毛 (non-Javadoc)

publicString toString() {if (front == null) {return "0";

}

String retval= front.digit + "";for (DigitNode curr = front.next; curr != null; curr =curr.next) {//if (curr.digit == 0&&Integer.parseInt(retval)!=0)

if (curr.digit == 0&&StrToInteger(retval))continue;

}if(negative) {

}returnretval;

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。