Problem:
Given an int n, return true if it is within 10 of 100 or 200. Note: Math.abs(num) computes the absolute value of a number.
nearHundred(93) → true
nearHundred(90) → true
nearHundred(89) → false
Solution:
public boolean nearHundred(int n) {
  int sum1 = Math.abs(n - 100);
  int sum2 = Math.abs(n - 200);
  
  if (sum1 <= 10 || sum2 <= 10)
    return true;
  else
    return false;
}
 

 
public boolean nearHundred(int n) {
ReplyDeletereturn (90 <= n && n <= 110) || (190 <= n && n <= 210);
}
return n>=90&&n<=110||n>=190&&n<=210;
ReplyDeletefor both sum1 and sum2 the value should be less than or equal to 10 so the code will be as
ReplyDeleteif(sum1<=10 || sum2<=10)