String Index Out Of Bounds Exception
807603Aug 26 2007 — edited Jan 31 2008import java.io.*;
public class Array
{
public static void main() throws Exception
{
System.out.println("Enter a word:");
BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
String ar1=br.readLine();
int n=ar1.length();
for(int i=0; i<n+1; i++)
{
if(ar1.charAt(i)=='a')
{
int sum=0;
sum=sum+1;
}
if(ar1.charAt(i)=='e')
{
int sum=0;
sum=sum+1;
}
if(ar1.charAt(i)=='i')
{
int sum=0;
sum=sum+1;
}
if(ar1.charAt(i)=='o')
{
int sum=0;
sum=sum+1;
}
if(ar1.charAt(i)=='u')
{
int sum=0;
sum=sum+1;
}
else
{
int num=0;
num=num+1;
}
for(int j=n; j>=0; j--)
{
System.out.print(ar1.charAt(j));
}
}
}
}
it is a program to count the number of vowels and consonants in a string entered by the user and then inverts it to check if it is a palindrome.
everytime i execute the program, it gives me a String Index Out Of Bounds Exception... what do i do?? the highlighted line is the one which has the exception...
thanks...
Message was edited by:
emii_dan