Please bear with me. I am new to java but I am struggling to code ..but I am sure I will overcome it one day so please help me ..
String array - Palindrome is what i am working on to build up my logical sense in java. This is what I have written so far
public class Strings1 {
public static void main(String[] args) {
String[] str = {"dadad", "Boomot", "mojmom"};
String[] str1=str;
String[] str2={};
int i=0;
int j=0;
int k=0;
char c='0';
char e='0';
int s = str.length;
System.out.println("number of elements in the array" + s);
try{
x: for(; i<s; i++){
y: for( j=i,k=str[i].length()-1; k>=0; j++,k--){ //j=0; k=5
c = (str[i].charAt(j)); // 0
e = (str[i].charAt(k)); //5
if(c==e)
{
str2[k] = Character.toString(c);
continue;
}
else
break y;
}
System.out.println(str[2]);
}
}catch (Exception ex){
ex.printStackTrace();
}
}
}
Error :- ------------ number of elements in the array3 java.lang.ArrayIndexOutOfBoundsException: 4 at Strings1.main(Strings1.java:25)
how should I go about it? Please help.