Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the result seems wrong

Tags:

java

my code will be display me That is not an acceptable input. if I insert negative number. then proceed to prompt the input. But it continue to calculate. this is part of my code contains something wrong. but i did not see.

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;

}
like image 687
Bolor Ch Avatar asked Dec 09 '25 15:12

Bolor Ch


1 Answers

you should write

if (oct < 0 || oct > 99999999 )

instead of

if (oct < 0 && oct > 99999999 )

|| stands for or, while && for and.

like image 181
onemach Avatar answered Dec 12 '25 03:12

onemach



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!