im not able to figure out the meaning of this piece of code:

public int void countTokens(String s)
{
StringTokenizer st= new StringTokenizer();
return st.countTokens();
}

Edited 5 Years Ago by __avd: Added [code] tags.

The adjective (public) given to a class meaning that it is accessible so you can use this public anywhere in your java project. (int void) means that it will return or give you an integer value. And this method takes/expects a String parameter which is specified in between the brackets and it is (String s). So you specify the data type before the variable name as you did in this example. So, the data type for "s" is "String".. I am not sure what's inside the body does if anyone does know it. Please explain it to us. Thanks in advance.

I hope this helps.

The declaration is wrong. There is no such thing as int void.
It is either int or void. And in this case it should be int:

public int countTokens(String s)
{
StringTokenizer st= new StringTokenizer();
return st.countTokens();
}

okay I found this piece of code in a JAVA EE book,and i knew something was wrong!
Thank you!

Are you sure that you've got that right?
I think it should be...
public int method_name () {} // which should return an int and requires a return statement
OR
public void method_name () {} // which should return nothing and does NOT require a return statement

I think it means the author of the book was tired and miss-typed :)

either that, or it was meant as an: can you see what's wrong here exercise

we use either one of the return type in method declaration...

either int or void.......

i this code cannot return anything..

code may be wrong..

u cannot use string parameter in the body also..

This question has already been answered. Start a new discussion instead.