Domanda di colloquio di Google

Convert decimal number 99 to base 7.

Risposte di colloquio

Anonimo

28 lug 2010

Uh, I think you meant 201 - perhaps this is why you didn't get the job. 99 = 2 * 7 * 7 + 1 = 2 * 7 ^ 2 + 0 * 7 ^ 1 + 1 * 7 ^ 0 = 201 Here's the code that does this in general: String convertToBase(int num, int radix) { StringBuilder sb = new StringBuilder(); int n = num / radix; int lsd = num % radix; do { sb.insert(0, lsd); lsd = n % radix; n /= radix; } while (n > 0); sb.insert(0, lsd); return sb.toString(); }

4

Anonimo

3 mag 2011

convert(n, r) if (n

Anonimo

23 lug 2010

101