Hi everyone,

I'm having a problem with understanding the workings of an enhanced For loop. This code is meant to iterate through an array of ints and print out the char value of that int. But it seems to start on the first number in the array, making the program throw an ArrayIndexOutOfBoundsException.

final int[] message = {60, 80, 100...}
		for(int i: message)
		{
			System.out.print((char)message[i]);
		}

any help would be great thanks.

You're misunderstanding the concept of a for each loop. Change the code to this:

final int[] message = {60, 80, 100...}
		for(int i: message)
		{
			System.out.print((char)i);
		}

Ahh.. it works, thanks so much.