## Facebook Interview Question for Android Engineers

Country: UK
Interview Type: Phone Interview

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````package com.test;

import java.util.HashMap;

class SolutionNumberToWords {
private static HashMap<Integer, String> places = new HashMap<>();
private static HashMap<Integer, String> pre = new HashMap<>();

public static void main(String args[]) {
places.put(0, "");
places.put(1, " thousand ");
places.put(2, " million ");
places.put(3, " billion ");

pre.put(1, "one");
pre.put(2, "two");
pre.put(3, "three");
pre.put(4, "four");
pre.put(5, "five");
pre.put(6, "six");
pre.put(7, "seven");
pre.put(8, "eight");
pre.put(9, "nine");
pre.put(10, "ten");
pre.put(11, "eleven");
pre.put(12, "twelve");
pre.put(13, "thirteen");
pre.put(14, "fourteen");
pre.put(15, "fifteen");
pre.put(16, "sixteen");
pre.put(17, "seventeen");
pre.put(18, "eighteen");
pre.put(19, "nineteen");
pre.put(20, "twenty");
pre.put(30, "thirty");
pre.put(40, "fourty");
pre.put(50, "fifty");
pre.put(60, "sixty");
pre.put(70, "seventy");
pre.put(80, "eighty");
pre.put(90, "ninty");

System.out.println(convertDigitToWord(1_234_560_701));
}

public static String convertDigitToWord(int digit) {
String output = "";

for (int i = 1; i <= 5 && digit > 0; i++) {
int newNumber = digit % (i * 1_000);
output = getStringFrom3Digit(newNumber) + places.get(i-1) + output;
digit /= 1_000;
}

return output;
}

private static String getStringFrom3Digit(int digit) {
String output = "";
if (digit / 100 > 0) {
output = pre.get(digit / 100) + " hundered";
}
digit = digit % 100;
if (pre.containsKey(digit)) {
output += " " + pre.get(digit);
}
else {
if (digit / 10 > 0) {
output += " " + pre.get((digit / 10) * 10);
}
digit = digit % 10;
if (digit > 0) {
output += " " + pre.get(digit);
}
}
return output;
}
}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.