[英]Can Java recognize variables placed in user input?
I'm new here. 我是新来的。 I'm wondering if Java can recognize variables input as a string. 我想知道Java是否可以将变量输入识别为字符串。
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? Java会将它(如果我输入Yn)识别为字母或变量吗? 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. 我问我正在尝试创建一个程序,该程序将适应Euler方法的多个公式。
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. 为了做这样的事情,你需要编写自己的基本解析器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.