As the title already reveals i am trying to calculate using no numbers also indices arent allowed, does anyone knows a good way to perform such operations?
I thought about using chars to calculate but then i dont know how to without using the ascii value of the character.
This here is my own number class i created, the goal would be to perform operations with object from the number class
class Number {
private LinkedList<Character> digits;
private boolean isNegative;
public Number(String number) {
digits = new LinkedList<>();
isNegative = number.startsWith("-");
for (char c : number.toCharArray()) {
if (Character.isDigit(c)) {
digits.add(c);
}
}
}
public Number() {
digits = new LinkedList<>();
isNegative = false;
}
public void addDigit(char digit) {
digits.add(digit);
}
public LinkedList<Character> getDigits() {
return digits;
}
public boolean isNegative() {
return isNegative;
}
public void setNegative(boolean isNegative) {
this.isNegative = isNegative;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(isNegative ? "-" : "");
for (Character digit : digits) {
sb.append(digit);
}
return sb.toString();
}
public static Number fromString(String str) {
return new Number(str);
}
}