aspose file tools*
The moose likes Beginning Java and the fly likes Command Line Arguments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Command Line Arguments

Stacey Johnson
Ranch Hand

Joined: Jan 11, 2004
Posts: 55
Hi Everyone,
In case you haven't guessed I'm working with command line arguments. I'm trying to have the user enter a word in the command line and the program tell the user if it is a palindrome or not. (Reminder: Palindrome is a word that is spelt the same forward and reverse ie) noon, mom, bob etc.) My text gives me the basics but the actual code is what I'm having problems with (obviously). I'm not sure I've stated my boolean method right. Again I'm new to all of this so some insight and explanation would help. I don't want to be told the code, I want to be given advise on what I need to be doing so I can figure it out my self. Below is what I have so far:


Thanks in advance
Stacey

(Marilyn added code tags for better readability)
[ February 11, 2004: Message edited by: Marilyn de Queiroz ]
Nischal Topno
Ranch Hand

Joined: Nov 24, 2001
Posts: 45
The code that you've put down will not compile at the first place. Re-look at your isPalindrome() method arguments and the use of those arguments in the method, things will fall in place
Loveen Jain
Ranch Hand

Joined: Jan 24, 2004
Posts: 35
Topno is right see your method definition of the isPalindrom, you havent specified that argument type in that definition.
~Loveen
Stacey Johnson
Ranch Hand

Joined: Jan 11, 2004
Posts: 55
I kinda get what you two are saying but the comand line argument (arg 0) is throwing me off. I really don't know where to go from here. I knew the code wouldn't compile and I realize because of the isPalindrome method but again I'm still lost.
Stacey
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11229
    
  16

args is just an array of strings. if you look at the signiature of main, it's public static void main (String [] args).
actually, "args" could really be any valid variable name - args, inputs, command_line_arguments... whatever.
so when at the command prompt you type:
c:\>java someProgram hello to you <enter>
the 3 input parameters ("hello", "to", and "you") are now in the array at args[0], args[1], and args[2]. I assume you know about arrays and how they are 0 indexed, right?
your program tests to make sure the user input EXACTLY ONE argument at the
if (args.length != 1)
line. then, assuming the user DID input one argument (which would be stored in an array of size 1, with the string at args[0]), you pass that string to your method to test for palindromity.
Hope that made some sense, and answers your question.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Nischal Topno
Ranch Hand

Joined: Nov 24, 2001
Posts: 45
same question is posted in two headings (Command Line Arguments, Please Help )... me getting confused where to reply and where actually the author is looking for answer and so where to reply.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Command Line Arguments