Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Question about Char Arrays

807599Apr 24 2007 — edited Apr 24 2007
I had this question in my homework:

Display the value of the seventh element of character array f.

I think I know the basic rules of integer arrays but I'm not sure they apply to character arrays. This is what I have:
public class CharArray
{
	public static void main( String args[] )
	{
		char f[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
		
		System.out.printf( "%s%8s\n", "Index", "Value" );
		
		for ( int counter = 0; counter = 6; counter++ )
			System.out.printf( "%5d%8d\n", counter, f[ counter ] );
	}
}  
Apparently, this doesn't work. I get the following error:

CharArray.java:9: incompatible types
found : int
required: boolean
for ( int counter = 0; counter = 6; counter++ )

Am I to understand that I can't use a counter to go through the subsequent elements in a char array like you would with a regular int array? Or do I just simply have a typo somewhere?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 22 2007
Added on Apr 24 2007
7 comments
281 views