mardi 2 janvier 2018

How to check for integer and less than or equal to 100 in an if/else statement

I have an if/else statement with a scanner in the conditions, as well as an && statement checking for the input being 100 or less. It goes like this:

Scanner input = new Scanner(System.in);

if(input.hasNextInt() && avgBefore <= 100) {

                avgBefore = input.nextInt();

            }

But if I put a number over 100 in, it still accepts it. Any help?

Aucun commentaire:

Enregistrer un commentaire