View difference between Paste ID: SK8xnDJG and DDaaMvnB
SHOW: | | - or go back to the newest paste.
1-
package org.gamboodle.vsf;
1+
2-
2+
3
    public static String equation = "((x^2)+3)";
4-
	   
4+
5
    public static void main(String[] args) {
6
        //checkForParenthesis(equation);
7
        System.out.println(checkForParenthesis(equation, 1));
8
    }
9
   
10
    public static String checkForParenthesis(String s, int n) {
11
        String equationNew = "";
12
        int openParenth = 0;
13
        int closedParenth = 0;
14
        for(int i = 0; i < s.length(); i++) {
15
            if(s.charAt(i) == '(') {
16
                openParenth++;
17
            }
18
            if(s.charAt(i) == ')') {
19
                closedParenth++;
20
            }
21
            if(openParenth == closedParenth) {
22
                if(openParenth > n) {
23
                    equationNew = equationNew.substring(1);
24
                    equationNew = equationNew.substring(0, equationNew.length()-1);
25
                    checkForParenthesis(equationNew, (n-1));
26-
                    equationNew = equationNew.substring(0, equationNew.length()-2);
26+
27-
                    checkForParenthesis(equationNew, (n));
27+
28
                if(openParenth == n) {
29
                    equationNew = equationNew + s.charAt(i);
30
                    break;
31
                }
32
                if(openParenth < n) {
33
                    equationNew = equationNew + s.charAt(i);
34
                    break;
35
                }
36
            }
37
            equationNew = equationNew + s.charAt(i);
38
        }
39
        return equationNew;
40
    }
41
 
42
    public static String checkForExponants(String s) {
43
        return "^";
44
    }
45
   
46
}