public class BigInteger {
// The sign of this integer - true for a positive number, and false
// otherwise
private boolean sign = true;
// digits[0] is the most significant digit of the integer, and
// the last element of this array is the least significant digit.
// For example, if we have a BigInteger of value 34, then
// digits[0] = 3 and digits[1] = 4.
private byte[] digits;
private int length;
public int lengths;
public BigInteger() {
this.digits = new byte[1];
this.digits[0] = 0;
}
public BigInteger(byte[] digits) {
this.digits = digits;
}
/**
* Initializes a <code>BigInteger</code> according to a string. The form of
* <code>numberStr</code> is a string consisting of all digits ranging from
* 0 to 9, following an OPTIONAL minus symbol (i.e., "-"). For example,
* "1234567891234567" and "-17788399934334388347734" are both valid.
*
* @param numberStr
* a number expressed as a string
*/
public BigInteger(String numberStr) {
char[] num =numberStr.toCharArray();
int len=num.length;
byte[] c=new byte[len];
for(int i=0;i<len;i++){
c[i]=Byte.parseByte(String.valueOf(num[i]));
}
this.lengths=len;
// YOU FILL THIS IN
// Note: You should parse the string and initialize the "digits" array
// properly.
// You may also need to set the "sign" variable to a correct value.
}
// The sign of this integer - true for a positive number, and false
// otherwise
private boolean sign = true;
// digits[0] is the most significant digit of the integer, and
// the last element of this array is the least significant digit.
// For example, if we have a BigInteger of value 34, then
// digits[0] = 3 and digits[1] = 4.
private byte[] digits;
private int length;
public int lengths;
public BigInteger() {
this.digits = new byte[1];
this.digits[0] = 0;
}
public BigInteger(byte[] digits) {
this.digits = digits;
}
/**
* Initializes a <code>BigInteger</code> according to a string. The form of
* <code>numberStr</code> is a string consisting of all digits ranging from
* 0 to 9, following an OPTIONAL minus symbol (i.e., "-"). For example,
* "1234567891234567" and "-17788399934334388347734" are both valid.
*
* @param numberStr
* a number expressed as a string
*/
public BigInteger(String numberStr) {
char[] num =numberStr.toCharArray();
int len=num.length;
byte[] c=new byte[len];
for(int i=0;i<len;i++){
c[i]=Byte.parseByte(String.valueOf(num[i]));
}
this.lengths=len;
// YOU FILL THIS IN
// Note: You should parse the string and initialize the "digits" array
// properly.
// You may also need to set the "sign" variable to a correct value.
}