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 …
我有一个叫做计算的方法
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测试来检查这一点?到目前为止我已经尝试过,但没有成功。一个好的理论答案就很好,不需要代码。