-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParserTests.java~
More file actions
29 lines (24 loc) · 965 Bytes
/
ParserTests.java~
File metadata and controls
29 lines (24 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public class ParserTests {
public static void main(String[] args){
//System.out.println(Parser.parse("5 + 5 * 5 / 5 - 5") + " ---5");
//System.out.println(Parser.parse("5 + 5 - 5") + " ---5");
//System.out.println(Parser.parse("5 * 5 / 5") + " ---5");
//System.out.println(Parser.parse("5 ^ ( 2 * 3 ) + 8") + "---15633");
//System.out.println(Parser.parse("2^3 - 3 + 1 + 3 * ((4+4*4)/2) / 5 + -5") + "---7");
//String expression = "5 + x";
//System.out.println(replaceVariables(22, expression)+"--- 5 + 22") ;
Function f = new Function("2^x - x + 1 + x * ((4+4*4)/2) / 5 + -5");
System.out.println(f.getValue(6.1645));
}
private static String replaceVariables(double x, String s)
{
for(int i = 0; i < s.length(); i++)
{
if(s.charAt(i) == 'x')
{
s = s.substring(0,i) + x + s.substring(i+1);
}
}
return s;
}
}