小编ift*_*wMZ的帖子

Java arrays produs of even positions

So, for example i have an array: int[] {1,2,3,4,5}. I need to print the product of even positions, 0 position will be considered even, so it will be: 1 * 3 * 5 = 15. When I am summing an array, I am doing something like this:

int sum = 0;
for (int i = 0; i < arr.length; sum += arr[i++])
Run Code Online (Sandbox Code Playgroud)

and I am receiving the answer correct.

Now, I thought of using the same method for …

java arrays for-loop

0
推荐指数
1
解决办法
115
查看次数

Mockito测试方法无效

我有一个叫做计算的方法

public class Calculator {
  public void calc(int a, int b){ 
    String condition = "first";
   int result = 0;

   if (condition.equals("first") { 
     condition = "no need";
   else { result = a + b;}
Run Code Online (Sandbox Code Playgroud)

之后打印结果,无论如何,我需要进行一个测试,看看条件值是否更改为“不需要”或保持“第一”,我如何使用mockito测试来检查这一点?到目前为止我已经尝试过,但没有成功。一个好的理论答案就很好,不需要代码。

java mockito

0
推荐指数
1
解决办法
38
查看次数

标签 统计

java ×2

arrays ×1

for-loop ×1

mockito ×1