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!

checking length of string from command line arguments

807601May 27 2008 — edited May 27 2008
I need to write a program that produces output from the command line arguments, i.e.:
java weekdays Monday Tuesday Wednesday Thursday Friday

Output would be:
Monday 6
Tuesday 7
Wednesday 9
Thursday 8
Friday 6
(the numbers on the right side represent the length of the string)

My program is:

1.public class weekdays {
2. public static void main(String[] args) {
3. for (int i=0; i<args.length; i++)
4. System.out.println(args[i] +"\t"+ length(args));
5. }
6.}

When I compile, I get an error message on line 4:
The method length(String) is undefined for the type weekdays.

From what I understand, args is an array of strings taken from command line arguments.
So I believe, that I am asking for the length of the string, when I say: length(args[i]).
Also, the length() method is part of the String class.
I don't understand why I am getting the error message and how to fix it.

thanx,
Izzy.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 24 2008
Added on May 27 2008
5 comments
2,184 views