-4 java
如果有人能在这段代码中找到错误,那对我有帮助.我正在使用Eclipse,我正在尝试制作一个只需按一下按钮即可发出单词/句子的程序.如果您需要更多信息,请询问.
错误:"if(this.boverall [a]!= 0){",ERROR message"运算符!=未定义参数类型boolean,int"
public String sentenceOverall()
{
ArrayList<String> toBeUsed = new ArrayList();
for (int a = 0; a < this.soverall.length; a++) {
if (this.boverall[a] != 0) {
toBeUsed.add(this.soverall[a]);
}
}
if (toBeUsed.size() == 2)
{
int sentencePattern = rand.nextInt(10);
if (sentencePattern < 9)
{
String[] OverallOptions = { " The song is overall both ", " Overall, the song is both ", " This song, overall, is both ", " Your song is quite ", " I think that the song is ", " I believe that your song is both ", " Your song is without a doubt ", " In my point of view, this is ", " First of all, thank you for creating this song. This song is very ", " Judging from my position, this song is ", " Personally, I think that the song is ", " All things taken together, I would say that this song is " };
Run Code Online (Sandbox Code Playgroud)
看来这boverall
是一个boolean
数组.试试这个:
if (this.boverall[a])
Run Code Online (Sandbox Code Playgroud)
我是怎么到达那种状况的?让我们一步一步看:
this.boverall[a] != 0 // this is wrong, can't compare int with boolean
this.boverall[a] != false // this is what you really meant to write
this.boverall[a] == true // if it's not false, then it can only be true
this.boverall[a] // equivalent to the above line, but shorter
Run Code Online (Sandbox Code Playgroud)
请记住,在Java(不像其他编程语言),一个boolean
是不是一个整数,特别0
是不一样的false
.
归档时间: |
|
查看次数: |
64 次 |
最近记录: |