A simple program to add polynomials
<p>Started java like a week ago. This may be a very silly mistake, but here goes the code: -</p>

<pre><code>import java.io.BufferedReader;
import java.io.InputStreamReader;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Kamat
 */
class AddPoly {

    public static void main(String args[]) {
        AddPoly obj = new AddPoly();
        obj.addPoly();
        System.out.println("Thank you for using the Polynomials adder v.708.76.");
    }

    void addPoly() {
        String expr = null;
        int num[] = new int[50];
        int pow[] = new int[50];
        int product[] = new int[50];
        int i=0, j=0, temp=0, fproduct = 0;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter a polynomial and its power like (5^4)+(6^3)   [Max 50 additions]");
        try {
            expr = br.readLine();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        char exp[];
        exp = expr.toCharArray();
        char numtemp[] = new char[expr.length()];
        char powtemp[] = new char[expr.length()];
        for (i = 0; i &lt; expr.length(); i++) {
            for (i++; exp[i] != '^'; i++) {
                numtemp[i] = exp[i];
            }
            for (i++; exp[i] != ')'; i++) {
                powtemp[i] = exp[i];
            }
            i = i + 2;
            String numtemp1 = new String(numtemp);
            String powtemp1 = new String(powtemp);
            num[j] = Integer.parseInt(numtemp1);
            pow[j] = Integer.parseInt(powtemp1);
            j++;
            for (int o = 0; o &lt; expr.length(); o++) {
            }

        }
        //Considering it goes as expected...
        for (i = 0; i &lt; 50; i++) {
            temp = num[i];
            for (j = 1; j != pow[i]; j++) {
                temp = temp * num[i];
            }
            product[i] = temp;
        }
        for (i = 0; i &lt; 50; i++) {
            fproduct = fproduct + product[i];
        }
        System.out.print("= ");
        for (i = 0; i &lt; 50; i++) {
            System.out.print(product[i] + " +");
        }
        System.out.println("");
        System.out.println("= " + fproduct);
    }
}
</code></pre>

<p>It gives the the following error wen I enter, eg. <code>(6^3)+(7^2)</code> (the '^' meaning "power of"):</p>

<pre><code>Exception in thread "main" java.lang.NumberFormatException: For input string: "
6         "
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at AddPoly.addPoly(addPoly.java:48)
    at AddPoly.main(addPoly.java:16)
</code></pre>

<p>It also didnt run on NetBeans (same code)</p>
