Java – the result seems wrong

My code will show me that this is not an acceptable input If I insert a negative number Then continue to prompt for input But it continues to count This is part of my code that contains errors But I didn't see it

public static boolean checkOctal()
{
    boolean b = true;
    if (oct < 0 && oct > 99999999 )
    {
        b = false;
        System.out.println("That is not an acceptable input.");
    }
    int tmp;
    int tmp1 = oct;
    while (tmp1 > 0)
    {
        tmp = tmp1 % 10;
        tmp1 = tmp1 / 10;
        if (tmp >= 0 && tmp < 8)
        {
            continue;
        } else
        {
            b = false;
            break;
        }
    }
    return b;

}

Solution

You should write

if(oct< 0 || oct> 99999999)

replace

if(oct< 0&& oct> 99999999)

||Represents or, and & & is and

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>