user3571264
user3571264

Reputation: 1

Can Java recognize variables placed in user input?

I'm new here. I'm wondering if Java can recognize variables input as a string.

Or, rather, would this work?

int Yn = 5;
System.out.println("please input the formula");
String x = keyboard.nextLine();

Will Java recognize it (if I input Yn) as letters or as a variable? If so, how could I make it recognize it as a variable? I ask as I am trying to create a program that will adapt to more than one formula for the Euler's method.

Upvotes: 0

Views: 89

Answers (1)

Code-Apprentice
Code-Apprentice

Reputation: 83527

No. Variable names are only known at compile-time. In order to do something like this, you will need to write your own basic parser.

Upvotes: 2

Related Questions