gpt4 book ai didi

java - 尝试检测 if 语句中的字符

转载 作者:行者123 更新时间:2023-12-01 18:44:45 25 4
gpt4 key购买 nike

我在检测 if 语句中的 CHAR 时遇到了一些麻烦。我有一个分数整数,我将其放入字符串中,然后从该字符串中,我制作了一个字符数组。我的问题是,当我尝试检测字符的数字时,它返回“Error.png”。

请帮助我:)

代码:

    scoreString = "" + score;
System.out.println(scoreString + " - " + scoreString.length());
scoreA = scoreString.toCharArray();
for(int counter = 0; counter < scoreString.length(); counter++){
Texture drawT;
if(scoreA[counter] == 0) drawT = i0;
else if(scoreA[counter] == 1) drawT = i1;
else if(scoreA[counter] == 2) drawT = i2;
else if(scoreA[counter] == 3) drawT = i3;
else if(scoreA[counter] == 4) drawT = i4;
else if(scoreA[counter] == 5) drawT = i5;
else if(scoreA[counter] == 6) drawT = i6;
else if(scoreA[counter] == 7) drawT = i7;
else if(scoreA[counter] == 8) drawT = i8;
else if(scoreA[counter] == 9) drawT = i9;
else drawT = error;
MainClass.batch.draw(drawT, 5 + (9 * counter), 95);
}

最佳答案

scoreA[counter] == 1 将字符与数值 1 进行比较,这是不正确的。 '1'1 不同。事实上,'1' 实际上等于十六进制的 31。使用类似的东西:

if(scoreA[counter] == '0') drawT = i0;
else if(scoreA[counter] == '1') drawT = i1;
//continue on

我显然包含了一个简短的片段,但这应该足够了。

关于java - 尝试检测 if 语句中的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18274429/

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