Java:为什么我会因为 if 语句而"';' expected"


构造

函数中的if应该检查输入是否合法...编译器似乎不同意我的观点,它在 if 语句后给了我"';"预期",我不明白为什么请帮忙。

public class RGBColor
{
    private int _red,_green,_blue;
    private final int _MAX_INTENSITY = 255,_MIN_INTENSITY = 0;
    /**
     * Constructor for objects of class RGBColor
     */
    public RGBColor()
    {
        _red = 0;
        _green = 0;
        _blue = 0;
    }
    public RGBColor(int red, int green,int blue)
    {
        If ((_red < _MIN_INTENSITY) || (_red > _MAX_INTENSITY) || (_green < _MIN_INTENSITY) || (_green > _MAX_INTENSITY) || (_blue < _MIN_INTENSITY) || (_blue > _MAX_INTENSITY)) \<<I get the error here
        {
            _red=0;
            _green=0;
            _blue=0;
        }
        else
        {
            _red = red;
            _green = green;
            _blue = blue;
        }
}
}

你的"If"有一个大写的"I",所以编译器认为你在声明一个类型。

最新更新