Question about Char Arrays

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:

publicclass CharArray

{

publicstaticvoid 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?

[1684 byte] By [Shadowplaya] at [2007-11-27 2:05:19]
# 1
Typo:for ( int counter = 0; counter < 6; counter++ )[Edit] Note the <. Nicer would be:for ( int counter = 0; counter < f.length; counter++ )
pbrockway2a at 2007-7-12 1:50:31 > top of Java-index,Java Essentials,New To Java...
# 2
Thanks!But the question says "Display the value of the seventh element of character array f.I take that to mean display ONLY the seventh value. Won't what your suggesting print out every value?
Shadowplaya at 2007-7-12 1:50:31 > top of Java-index,Java Essentials,New To Java...
# 3
System.out.println(f.length); // 7
rym82a at 2007-7-12 1:50:31 > top of Java-index,Java Essentials,New To Java...
# 4

> Thanks!

>

> But the question says "Display the value of the

> seventh element of character array f.

>

> I take that to mean display ONLY the seventh value.

> Won't what your suggesting print out every value?

Array tutorial

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html

rym82a at 2007-7-12 1:50:31 > top of Java-index,Java Essentials,New To Java...
# 5
I don't understand how this helps. It prints out the length of the total array. I understand that, but I'm trying to get a specific element out of the array.
Shadowplaya at 2007-7-12 1:50:31 > top of Java-index,Java Essentials,New To Java...
# 6
reply #3 told you that you have misunderstanding on Array even you follow the comment given by pbrockway2.reply #4 gave the link directing to a tutorial of Array which you would find the answer
rym82a at 2007-7-12 1:50:31 > top of Java-index,Java Essentials,New To Java...
# 7
Yes, ok thank you.I see what I was doing wrong now.
Shadowplaya at 2007-7-12 1:50:31 > top of Java-index,Java Essentials,New To Java...