title: Problems with BigInteger in Java
body: <p>Maybe this question is silly, but I'm new in Java and I cant figure this out...</p>
  
  <p>So I have two clases - Digit and BigDigit and the problem is here <code>Digit2.sub(Digit1);</code> when Digit1 is negative I get </p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.NumberFormatException: Illegal embedded sign character
        at java.math.BigInteger.(Unknown Source)</p>
  </blockquote>
  
  <p>but when I tried pass as argument not Digit1, but example "-18370", then everything is ok, but basically it should be the same. If it's positive, everyting works like a charm. Can anyone give me a tip where I went wrong? Method 'add' works all the time, but 'sub' only with positive Digit1.</p>
  
  <p><strong>UPDATED</strong>
  This code works when <code>Digit1</code> is positive or if uncomented <code>Digit1.add( Digit2);</code>, then works when sum is positive. But not negative :(</p>
  
  <pre><code>import java.math.BigInteger;
  
  public class Digit {
  
  public static void main(String[] args)
  {
      BigDigit Digit1 = new BigDigit("-18730");
      BigDigit Digit2 = new BigDigit("77730");
  
     // Digit1.add( Digit2);
      Digit1.display();
      Digit1.reverse();
      Digit1.display();
  
     Digit2.sub( Digit1);
     Digit2.display();
     Digit2.reverse();
     Digit2.display();
      }
  }
  class BigDigit {
  public String number;
  public BigInteger first;
  public BigInteger second;
  
  public BigDigit(String str) {number = str;}
  
  public String add(BigDigit sk) {
      first = new BigInteger(number);
      second = new BigInteger(sk.number);
      return number = first.add(second).toString();
  }
  
  public String reverse() {
      return number = new StringBuffer(number).reverse().toString();
  }
  
  public void sub(BigDigit sk) {
      first = new BigInteger(number);
      second = new BigInteger(sk.number);     
      }
  public void display() {System.out.println(number);}
  }
  </code></pre>