Friday, June 3, 2016

Java Challenge - nearHundred - warm_up

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

Hisoka's code:
1
2
3
public boolean nearHundred(int n) {
  return((Math.abs(n-100) <= 10)||(Math.abs(200-n) <= 10));
}

Output:

Codingbat code:
1
2
3
4
public boolean nearHundred(int n) {
  return ((Math.abs(100 - n) <= 10) ||
    (Math.abs(200 - n) <= 10));
}

Hohoho... Mirip... :D

No comments:

Post a Comment