【发布时间】:2020-12-31 14:49:13
【问题描述】:
int[] array2 = new int[]{1,2,6,6,3,1,};
//method checks if the given array contents remain the same when array is reversed
public static boolean verify(int[] array, int index) {//method takes array and an index number
if ((array[index] == array[array.length - index-1]) && (index < array.length/2)) {
System.out.print("true/");
verify(array, ++index);// increase index number to check the next values in the th array
return true;
} else
System.out.println("..false..");
return false;
}
【问题讨论】:
-
第一个如果做
return verify(array, ++index) -
@azro 仅此一项是不够的。此更改将始终返回
false。 -
在 arzo 说的之后,在函数的开头添加一个基本情况的条件,如
if(index >= array.length/2) return true; -
你是不是想说
array.length - (index - 1)? -
添加你正在传递的索引
标签: java recursion return boolean-logic