Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Cheryl Oliver
Cheryl Oliver
21,676 Points

Checking a variable is between 100 and -100

Hi Guys, does anyone know the answer to this? Please write a function to check that the given variable is a number between -100 and 100, and not zero.

2 Answers

int number;

public boolean isTrue(){
    if(number <= 100 && number >= -100) {
        return true;
}else {
    throw new IllegalArgumentException("Does not apply.");

I think this should do it. I am a beginner so maybe not.

Oh yea, i forgot that it needs to not be zero. You can change that by adding '&& number != 0' in the 'if' statement's condition.