File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

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

(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.
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.
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11175

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:
subject: Command Line Arguments
Similar Threads
Please Help
palindrome program
palindrome not very proficient...
Palindrome example