0
Is it possibly to read a double value from a string and evaluate it in java
11 Respostas
+ 5
String str = "0.5";
Double d;
d = Double.parseDouble(str);
+ 2
bruce Gmeskel
Can you please give a detailed example.
How does f(x) looks like?
+ 2
Do you have a code where I can see it?
Btw: If you want to replace x you should have a look into the StringBuilder class.
StringBuilder is mutable and contains a replace method.
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/StringBuilder.html
https://www.google.com/amp/s/www.geeksforgeeks.org/stringbuilder-class-in-java-with-examples/amp/
0
Can you please give one example
0
String str={"0.5"};
Double d;
I wanted to store 0.5 into d
0
Okay but i am trying to do a program that accept f(x) and evaluate it with an interval and i proceed with an infix evaluation method of stack but i cant accept a double value ?
0
Any mathematical functions sucha as polynomial like X^3+x
0
And which part of it is your wanted double value?
Sorry I am not so good in math ;)
But I guess you first need to split the String to separate each part of your function.
And than it should be possible to get your double value.
0
Yes that's right i separated intothe strings into char arr the i wantedvto replace the x variable by an interval or value so i tried to convert the interval which is double to string and store it on string but it only store the last value for instance 0.5 is my interval but it stores only 5
0
Here is the code
https://code.sololearn.com/c52su0vzu6u3/?ref=app
0
Thank you guys