Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
648 views
in Technique[技术] by (71.8m points)

java - The operator < is undefined for the argument type(s) boolean, int

I am new to processing and I am having trouble with this. I keep getting an error message for the bolded part of the code below. Is my syntax wrong?

void block(int x, int y, int s, color tinto) {
    fill(tinto);
    for (int i = 0; i < 3; i++) {
        triple(x, y+i*s, s, tinto);
    }
    if (0 < i < 3 && 6 < i < 9) {  // HERE
        tinto = 255;
    }
    else {
        tinto = tinto - 200;
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In Java, to check if a variable is in a range you have to divide the statement into two parts, like this:

if (0 < i && i < 3 && 6 < i && i < 9){

}

This specific code will never be true, however, because you're asking for it to be in two different ranges. Perhaps you meant to check for either range?

if (0 < i && i < 3 || 6 < i && i < 9){

}

Note the || or operator instead of the && and operator.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...