Win a copy of Design for the Mind this week in the Design forum!
    Bookmark Topic Watch Topic
  • New Topic

Command Line Arguments

 
Stacey Johnson
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Report post to moderator
Topno is right see your method definition of the isPalindrom, you havent specified that argument type in that definition.
~Loveen
 
Stacey Johnson
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Pie
Posts: 12098
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
Nischal Topno
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
    Bookmark Topic Watch Topic
  • New Topic