Pergunta de entrevista da empresa Vrbo

The programming question consisted of writing a program to sum up the elements in an array that are divisible by two numbers given. So let's say you have an array [1, 2, 3, ... 10]. Then given two numbers, say 3 and 5, you want to sum up the numbers divisible by 3 or 5 in that array and return the value. So it would be 3+5+6+9+10. Also he asked me some general programming questions like what inheritance is and what the difference between an object and a class is.

Resposta da entrevista

Sigiloso

31 de out. de 2013

int sum(int[] nums, int a, int b) { int retSum = 0; for(int i = 0; i < nums.length; i++) if((nums[i] % a == 0) || (nums[i] % b == 0)) retSum += nums[i]; return retSum; }