I need to overload constructor of the BigInteger class to create an instance of VeryLong from int and long. Here is my code:
private ArrayList<Long> A = new ArrayList<>();
private VeryLong(int n) {
while (n > 0) {
A.add(long()(n % 10));
n /= 10;
}
while (!A.isEmpty()) {
System.out.println(A.get(0));
A.remove(0);
}
}
private VeryLong(long n) {
while (n > 0) {
A.add(n % 10);
n /= 10;
}
while (!A.isEmpty()) {
System.out.println(A.get(0));
A.remove(0);
}
}
If I define A as ArrayList of Long there goes error in first constuctor. Similarly, it's error in add() method in second, if i define A as Vector<Integer> A = new Vector<Integer>();. How can I fix it?
Vector? Can we see the error? Where doBigIntegerconstructors come into this?intandlong? Thelongone would do the same as theintone. And why add to anArrayListonly to remove it all again?ArrayList<Long>,ArrayList<Integer>(orArrayList<Byte>) is just fine for both constructors. You need to learn the proper casting syntax.