Hey, I'm doing this program (it's very simple) and I can't find the error in the code!
all it has to do, is see if the number has "a reflection" in the array.Code:import java.util.Random;
public class NúmerosEnteros{
private int []s;
public NúmerosEnteros (int n, Random azar){
s=new int [n]; int a=0;
for (int k=0; k<n; k++){
a=azar.nextInt(10);
s[k]=a;}}
public boolean tieneReflejo(){
return (tr(0, s.length-1));}
public boolean tr(int a, int b){
if (b<=a) return false;
else
if(s[a]==s[b]) return true;
else return (tr(a++,b--));}
}
it means that if the array is empty or has just one element, it doesn't have a reflection.
in other case:
you all know the array saves numbers like this
d0 d1 d2 d3... d(n-1) dn
so, if d0=dn, or d1=d(n-1), or d2=d(n-2), etc., then it has a reflection.
else, it doesn't.
can someone tell me where the error is? I can't find it.
EDIT: Moved post to this thread

