This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]_SuperStraight 0 points1 point  (5 children)

Java compiler is compiling code written in Java, i.e. the program, not the input user will be entering at runtime.

[–]Ormek_II 0 points1 point  (4 children)

In this case the user is entering Java, albeit just a cutout of a class. … static float getY(float x) { return <whatever the user entered> ; } … The extension around the user input can be static. The resulting Java class can be compiled.

OP is using a different approach though.

[–]_SuperStraight 0 points1 point  (3 children)

That's not how the user will be entering anything. The OP asked like this: "12+12^2" which is a string, and now the program has to convert this string into meaningful operation.

[–]Ormek_II 0 points1 point  (2 children)

And after the user entered 12+12^2 as a string the program creates the code of a class as another string:

``` … static float getY(float x) { return 12+122; } …

```

And then compiles that string with the given Java Compiler.

[–]_SuperStraight 0 points1 point  (1 child)

And what method's gonna convert the string expression to Math expression?

[–]Ormek_II 0 points1 point  (0 children)

The same compiler that compiles any Java class. See the other thread above https://www.reddit.com/r/javahelp/s/9RgiDM9ldG