开发者

Java "OR", having problems

My problem is next:

I need to check if program.version (major, minor) is 1.5 (where 1 is major, 5 is minor version) or higher, or lower... So I need some something like this:

if (major < 2 && minor > 4) || (major > 1 ) // if version is higher then 1.5 or 2
{
//code//
}
if (major < 2 &开发者_JS百科& minor < 5)
{
//code//
}

The problem is in "||", it reports the syntax error on token "||"... and I don't know how to solve the problem. Any help please?!


You've only forgot a parenthesis..

if ((major < 2 && minor > 4) || (major > 1 ))


You're parenthese are wrong.

if ( (major < 2 && minor > 4) || (major > 1) ) // if version is higher then 1.5 or 2
{
//code//
}
if (major < 2 && minor < 5)
{
//code//
}


you're missing the parathesis on the first if statement line

make it

if ((major < 2 && minor > 4) || (major > 1 ))


In Java "if" expression always must be enclosed in brackets.

Just change for

if ((major < 2 && minor > 4) || (major > 1 ))
{
//code//
}

and your compiler will be happy.

Cheers


check your brackets -

if ((major < 2 && minor > 4) || (major > 1 ) )


You appear to be missing a set of brackets. The expression being testing in the if-statement must be surrounded by brackets e.g.

    if ((major < 2 && minor > 4) || (major > 1 )) // if version is higher then 1.5 or 2
    {
    //code//
    }
    if (major < 2 && minor < 5)
    {
    //code//
    }


Instead of checking for major and minor seperately, just multiply your version with either 100 or 1000 and then have your comparision numbers accordingly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜