I have a problem in this recursion exercise.
The exercise is to test whether the array of characters has only uppercase or lowercase and only then return true; otherwise if there are both lowercase and uppercase letters, return false.
The code below always returns true.
I try to put a variable to count every time there is a large or small signal and then if the amount is equal to the array so it is true otherwise it is not true; but it does not give me that. It is a Boolean function and call recursion is not giving me the amount of the variable.
The code:
public static boolean Arr(char[] arr, int length) {
if (length == -1)
return true;
boolean flag = Character.isUpperCase(arr[length]);
if (flag)
return true;
return Arr(arr, length - 1);
}