gpt4 book ai didi

java - 确定字符数组列表中的变量 Java

转载 作者:行者123 更新时间:2023-12-02 07:57:13 27 4
gpt4 key购买 nike

嗨,我有一个字符数组列表,其中存储了我的逻辑表达式。我的代码计算列表中的变量,我的问题是当我有相同的变量但有一个非符号和一个括号时。例如:xy+zy'变量数应为4,y和y'不同​​。

public void simplify(String strexp){

int length = strexp.length();

//get the size and variables used in expression
List<Character> usedVariables = new ArrayList<Character>();
for (int i = 0; i < length; i++) {
char c = strexp.charAt(i);
if (Character.isLetter(c) && !usedVariables.contains(c)&&usedVariables.contains('\'')) {
usedVariables.add(c);
}
}
}

最佳答案

如果您的变量可能长于一个字符,您应该考虑字符串数组列表,而不是字符。

关于java - 确定字符数组列表中的变量 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9454095/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com