View Allnum of num

Associate Software Engineer Interview Austin, TX

WebsenseAnswer## Write a program on the whiteboard such that sum(n) returns

the sum of all the numbers up to the nth number in the sequence {0, 1, 1, 2, 3, 5, 8, 13, ...} (I noticed that this was the Fibonacci sequence but he did not call it that). Given 9 balls designed to be identical, what is the best method to find the faulty ball in the least amount of steps given only a balance scale. That is, you have 9 balls and one of them is either heavier or lighter than the others. Write a simple calculator program that allows a user to give an input (example: 5*3+4/3-4*1) and the program computes the integer result accounting for order of operations (example: 5*3+4/3-4*1 = 15+0-4 = 11)

1 Answer

To comment on this, Sign In or Sign Up.

Would you like us to review something? Please describe the problem with this {0} and we will look into it.

Your feedback has been sent to the team and we'll look into it.

working java code for sum function (with print out to better understand):

public static int sum(int[] n)

{

int x = 0;

for(int i = 0; i < n.length - 1; i++)

{

System.out.println("x: " + x);

x = x + n[i];

System.out.println(" + " + "n[i]: " + n[i]);

}

return x;

}