nearHundred

Given an int n, return true if it is within 10 of 100 or 200. Note Math.abs(n) returns the absolute value of a number.

nearHundred(93) -> true
nearHundred(90) -> true
nearHundred(89) ->false

public boolean nearHundred(int n) {
if((Math.abs(100 - n) <= 10) || (Math.abs(200 - n) <= 10)) return true;
else return false;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s