Zynga Interview Question
Software Engineer in Tests#
#
#write a function that takes two numbers a and b and returns a.b eg: a=10 and b=12 output will be 10.12
#
#
#
import math
#def to_decimal(a, b):
# return float(str(a) + "." + str(b))
def to_decimal(a, b):
if b is not 0:
return a + (float(b) / (10.0 ** (math.floor(math.log10(b) + 1.0))))
else:
return a + 0.0
print to_decimal(567, 789)
print to_decimal(1234, 567)
print to_decimal(1234, 000)
print to_decimal(1234, 100)
package number.manipulation;
/* write a function that takes two numbers a and b and returns a.b eg: a=7 and b=24 output will be 7.24 */
public class NumberManipulation {
public double create(int a, int b) {
int n = b;
int count = 0;
while (n > 0) {
count++;
n /= 10;
}
return (double) a + ((double) b / Math.pow(10, count));
}
public static void main(String[] args) {
NumberManipulation nm = new NumberManipulation();
double result = nm.create(7, 24);
System.out.println(result);
}
}
import java.util.*;
- Anonymous March 26, 2012public class HelloWorldApp {
public static double numberAdd(int a, int b)
{
double A = (double)a;
double B = (double)b;
while (B>=1)
{
B = B/10;
}
return A+B;
}
public static void main(String[] args) {
int a=10,b=12;
System.out.println(numberAdd(a,b));
}
}