即使输入有下划线,此代码也会返回 false。 输入类似于 1_3/4 + 3 并返回 4_3/4
String[] Separated = fraction.split(" "); //Splits the tokens up
String firstToken = Separated[0]; // I created this to try to troubleshoot
boolean Mixed = true; //This would determine how much I will need to split up
for(int i = 0; i < firstToken.length(); i++) {
if(firstToken.charAt(i) == '_') {
Mixed = true;
}
else {
Mixed = false;
}
}
最佳答案
您可以使用“contains”代替 for 循环:
boolean mixed = firstToken.contains("_");
请在java中使用小写变量名。
关于java - charAt 无法在 Java 分数计算器中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47561368/