@Test public void testGetLevelForXp() { int level = Experience.getLevelForXp(XP_FOR_99); Assert.assertEquals(99, level); level = Experience.getLevelForXp(XP_FOR_99 - 1); Assert.assertEquals(98, level); level = Experience.getLevelForXp(XP_FOR_126); Assert.assertEquals(126, level); level = Experience.getLevelForXp(XP_FOR_126 - 1); Assert.assertEquals(125, level); level = Experience.getLevelForXp(Integer.MAX_VALUE); Assert.assertEquals(126, level); level = Experience.getLevelForXp(0); Assert.assertEquals(1, level); }
public static int getLevelForXp(int xp) { if (xp < 0) { throw new IllegalArgumentException("XP (" + xp + ") must not be negative"); } int low = 0; int high = XP_FOR_LEVEL.length - 1; while (low <= high) { int mid = low + (high - low) / 2; int xpForLevel = XP_FOR_LEVEL[mid]; if (xp < xpForLevel) { high = mid - 1; } else if (xp > xpForLevel) { low = mid + 1; } else { return mid + 1; } } return high + 1; }
Experience { public static int getLevelForXp(int xp) { if (xp < 0) { throw new IllegalArgumentException("XP (" + xp + ") must not be negative"); } int low = 0; int high = XP_FOR_LEVEL.length - 1; while (low <= high) { int mid = low + (high - low) / 2; int xpForLevel = XP_FOR_LEVEL[mid]; if (xp < xpForLevel) { high = mid - 1; } else if (xp > xpForLevel) { low = mid + 1; } else { return mid + 1; } } return high + 1; } }
Experience { public static int getLevelForXp(int xp) { if (xp < 0) { throw new IllegalArgumentException("XP (" + xp + ") must not be negative"); } int low = 0; int high = XP_FOR_LEVEL.length - 1; while (low <= high) { int mid = low + (high - low) / 2; int xpForLevel = XP_FOR_LEVEL[mid]; if (xp < xpForLevel) { high = mid - 1; } else if (xp > xpForLevel) { low = mid + 1; } else { return mid + 1; } } return high + 1; }  }
Experience { public static int getLevelForXp(int xp) { if (xp < 0) { throw new IllegalArgumentException("XP (" + xp + ") must not be negative"); } int low = 0; int high = XP_FOR_LEVEL.length - 1; while (low <= high) { int mid = low + (high - low) / 2; int xpForLevel = XP_FOR_LEVEL[mid]; if (xp < xpForLevel) { high = mid - 1; } else if (xp > xpForLevel) { low = mid + 1; } else { return mid + 1; } } return high + 1; }  static int getXpForLevel(int level); static int getLevelForXp(int xp); static double getCombatLevelPrecise(int attackLevel, int strengthLevel,
		int defenceLevel, int hitpointsLevel, int magicLevel,
		int rangeLevel, int prayerLevel); static int getCombatLevel(int attackLevel, int strengthLevel,
		int defenceLevel, int hitpointsLevel, int magicLevel,
		int rangeLevel, int prayerLevel); }
Experience { public static int getLevelForXp(int xp) { if (xp < 0) { throw new IllegalArgumentException("XP (" + xp + ") must not be negative"); } int low = 0; int high = XP_FOR_LEVEL.length - 1; while (low <= high) { int mid = low + (high - low) / 2; int xpForLevel = XP_FOR_LEVEL[mid]; if (xp < xpForLevel) { high = mid - 1; } else if (xp > xpForLevel) { low = mid + 1; } else { return mid + 1; } } return high + 1; }  static int getXpForLevel(int level); static int getLevelForXp(int xp); static double getCombatLevelPrecise(int attackLevel, int strengthLevel,
		int defenceLevel, int hitpointsLevel, int magicLevel,
		int rangeLevel, int prayerLevel); static int getCombatLevel(int attackLevel, int strengthLevel,
		int defenceLevel, int hitpointsLevel, int magicLevel,
		int rangeLevel, int prayerLevel); static final int MAX_VIRT_LEVEL; }