public class Reverse {
public static void main(String[] args) {
char name[]="prakash".toCharArray();////initialisng array
////////swapping string order//////////////
//////////i.e. reversing array of characters//////////
for(int i=0;i<=(name.length)/2;i++)
{
int j=name.length-i;
char temp;
temp=name[i];
name[i]=name[j];
name[j]=temp;
}
}
}
I am getting the following error: java.lang.ArrayIndexOutOfBoundsException. What is wrong with the code?
Array indices are zero-based: the “first” element is at 0, the “last” element is at
length-1.Therefore, if you want
jto go down from the last element, it should be