Zynga Interview Question for Software Engineer in Tests






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

import java.util.*;
public 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));



}





}

- Anonymous March 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

public double twoIntToDouble(int a, int b){
		int lengthOfB = (b ==0) ? 1 : (int)Math.log10(b) + 1;
		return a + b /Math.pow(10, lengthOfB);
	}

- Anonymous June 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public double twoIntToDouble(int a, int b){
		int lengthOfB = (b ==0) ? 1 : (int)Math.log10(b) + 1;
		return a + b /Math.pow(10, lengthOfB);
	}

- hubert June 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Simple Answer use macro to generate this output

- Anonymous June 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Why not just do a string concatenation operation?

- Anonymous October 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is my solution using a C/C++ style string concatenation approach:

double oneNumberDotTheOther(int a, int b)
{
ostringstream oVV;
oVV << a << "." << b;
string zVV = oVV.str();
double fVal = atof(zVV.c_str());
return fVal;
}

- Anonymous November 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public double concatDecimal(int a, int b){
return Double.parseDouble(a + "." + b);
}

- Anonymous December 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Do people just think the case b has more than 2 digits?

- Anonymous March 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Ofcourse. it could be any number of digits that fit an integer

- va July 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#
#
#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)

- Anupam Sharma October 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int a =10;
		int b = 12;
		String c = a + "." + b;
		System.out.println(c);

Alternatively you can also return the variable c

- vinodjayachandran February 03, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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);
	}

}

- jasmine August 06, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int a,b;
cin>>a>>b;
string result=to_string(a) + '.' + to_string(b);
cout<<result<endl;

- pcbindian January 30, 2016 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More