I’m making a few random classes that do various things at the moment but I’m slightly stuck on this method. Every time I run the below program it works perfectly except it throws an array index out of bounds exception before it finishes; I know the cause of the problem but the only way I can think of fixing it would be to find some way to have an ‘is not greater than’ operator to make sure that z never goes past the end of the char array.
If anyone can figure out a fix to this it would help. Maybe I’ll get lucky and figure it out myself soon. =)
class MessageDisplay
{
public MessageDisplay()
{
}
public static void typeWriterDisplay(String x)
{
char[] array = x.toCharArray();
int i = 0;
int z = 0;
while( i <= x.length() )
{
System.out.println( array[z] );
z++;
}
}
public static void main(String args[])
{
typeWriterDisplay("Lololol");
}
}