First digit in product of an array of numbers | Java implementation to find first digit of a single number ; Keep dividing by 10 until it is greater than equal to 10 ; Driver method
class Test { static int firstDigit ( int x ) { while ( x >= 10 ) x = x / 10 ; return x ; } public static void main ( String args [ ] ) { System . out . println ( firstDigit ( 12345 ) ) ; System . out . println ( firstDigit ( 5432 ) ) ; } }