so i am trying to wright a program to Print a word with all of the vowels replaced with $. in java.
i keep getting this error exception in thread main java.lang.StringIndexOutOfBoundsException: String index out of range: 6
when i run it, it compiles fine.
here's the code.
import java.util.*;
public class SummerFour
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int cnt = 0;
String word;
String output = "";
char letter = 'x';
System.out.print("enter word to test: ");
word = keyboard.nextLine();
do {
cnt++;
letter = word.charAt(cnt - 1);
if (letter == 'a' || letter == 'i' || letter == 'e' || letter == 'u' || letter == 'o')
{
letter = '$';
}
}
while (cnt <= word.length());
System.out.println(word);
}
}