• Post Reply Bookmark Topic Watch Topic
  • New Topic

command line arguments  RSS feed

 
Bob Chandler
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand how command line arguments are passed into a
program as an array of Strings through the main method.
My problem occurs when I want to check that the user has
actually entered an argument before I try to manipulate the values.
if I write...

I get an error
Should I be using the equals method?
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
something like:

is more suitable
 
Jeffrey Spaulding
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
since args is an array you can check the length with
if ( args.length == 0 ) {
System.out.println("No arguments, quitting now");
// ...
}
 
Bob Chandler
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you guys!
you just turned my frown upside down.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!