简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM