How in Java do you return the first digit of an integer.?
i.e.
345
Returns an int of 3.
public static int firstDigit(int n) { while (n < -9 || 9 < n) n /= 10; return Math.abs(n); }
Should handle negative numbers pretty well, too. Will return a negative first digit in that case.