0
This is my method:
public static void B()
{
int vet[]=new int [100];
int vet2[]=new int [vet.length/2];
for(int i=0;i<=vet.length;i++)
{
vet[i]=i+1;
}
for(int i=0;i<vet.length;i++)
{
int rest = vet[i]%2;
if(rest==0)
{
vet2[i]=vet[i];
}
}
for (int i = 0; i <= vet2.length; i++)
{
if(vet2[i]==(vet2[i-1])-i)
{
System.out.println(vet2[i]+"É PALINDROMO");
}
}
And this is the error that appears:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100 at lista1.pkg05.Lista105.B(Lista105.java:59) at lista1.pkg05.Lista105.main(Lista105.java:15) C:\Users\Pichau\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53:
Java returned: 1
This code has some errors, but we need to know its goal to fix, especially in the last loop that certainly makes account wrong. If you are going to find out if a array is the inverse of the other, it is obvious that in this algorithm is not.
– Maniero
Hello Fernando, could you please explain what you want? Either only the code correction or actually the algorithm to check if the number is palindromic?
– Randrade