Question d’entretien chez Google

Convert decimal number 99 to base 7.

Réponses aux questions d'entretien

Utilisateur anonyme

28 juil. 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

Utilisateur anonyme

3 mai 2011

convert(n, r) if (n

Utilisateur anonyme

23 juil. 2010

101