Pergunta de entrevista da empresa Amazon

Write a function that takes an integer and prints out the digits separated by commas. Example, pass in 345 print out 3,4,5

Respostas da entrevista

Sigiloso

22 de dez. de 2010

Void parseDigits(int Number) { string format = ""'; while(num > 0) { quotient = num%10; if(num > 9) format = format + quotient.ToString() + ","; else format = format + quotient.ToString(); num = num/10; } Format.Reverse(); //should give desired number with digits seperated with comma; }

Sigiloso

23 de fev. de 2011

without reverse: firstdig = num/100 ;integer division will give you first digit print firstdig print "," num -= firstdig * 100 seconddig = num/10 print seconddig print "," print num num -= seconddig *10

Sigiloso

6 de mar. de 2011

slightly lazier version: public static void printIntStringMath(int theInt) { StringBuffer result = new StringBuffer(); while(theInt > 0) { result.append("," + theInt % 10); theInt = theInt / 10; } result.deleteCharAt(0); System.out.println(result.reverse()); }

Sigiloso

20 de mar. de 2012

public static void main(String [] args){ int j = 345890; String line = j+""; int len = line.length(); int i = 0; while(i