473,505 Members | 14,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with command line arguments

2 New Member
Hi, I am working on a java program for my class where I have to rewrite a code that checks whether the input is a palindrom by passing the string as a command-line argument.
Here is the code that I have to rewrite. PLEASE HELP!!
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane;
  2.  
  3. public class CheckPalindrome
  4. {
  5.     public static void main(String [] args)
  6.     {
  7.         String s = JOptionPane.showInputDialog("Enter a string");
  8.  
  9.         String output = "";
  10.  
  11.         if(isPalindrome(s))
  12.             output = s + " is a palindrome.";
  13.         else
  14.             output = s + " is not a palindrome.";
  15.  
  16.         JOptionPane.showMessageDialog(null, output);
  17.     }
  18.  
  19.     public static boolean isPalindrome(String s)
  20.     {
  21.         int low = 0;
  22.  
  23.         int high = s.length() - 1;
  24.  
  25.         while(low < high)
  26.         {
  27.             if(s.charAt(low) != s,charAt(high))
  28.                 return false;
  29.  
  30.             low++;
  31.             high--;
  32.         }
  33.         return true;
  34.     }
  35. }
  36.  
Apr 17 '07 #1
6 3996
dmjpro
2,476 Top Contributor
welcome to TSDN

u r trying to compare the first half characters and the last half characters.
is this right to check a string .... palyndrom????

what J2SE version u r using????
there r lot of APIs ..... handling with string.

if u r using Swing then why r u having main function?????

and one more thing .... ur Q. title is related to command line arguments, but u have not used this.......

so at the end i totally mess up.....would u be more clear???
Apr 17 '07 #2
r035198x
13,262 MVP
Hi, I am working on a java program for my class where I have to rewrite a code that checks whether the input is a palindrom by passing the string as a command-line argument.
Here is the code that I have to rewrite. PLEASE HELP!!
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane;
  2.  
  3. public class CheckPalindrome
  4. {
  5.     public static void main(String [] args)
  6.     {
  7.         String s = JOptionPane.showInputDialog("Enter a string");
  8.  
  9.         String output = "";
  10.  
  11.         if(isPalindrome(s))
  12.             output = s + " is a palindrome.";
  13.         else
  14.             output = s + " is not a palindrome.";
  15.  
  16.         JOptionPane.showMessageDialog(null, output);
  17.     }
  18.  
  19.     public static boolean isPalindrome(String s)
  20.     {
  21.         int low = 0;
  22.  
  23.         int high = s.length() - 1;
  24.  
  25.         while(low < high)
  26.         {
  27.             if(s.charAt(low) != s,charAt(high))
  28.                 return false;
  29.  
  30.             low++;
  31.             high--;
  32.         }
  33.         return true;
  34.     }
  35. }
  36.  
Could you tell us what specific problem you have with this.
Apr 17 '07 #3
LyndsayJ
2 New Member
Could you tell us what specific problem you have with this.
I thought I was specific...I have to rewrite the code that I posted in my original message so that I pass the input as a command line argument...rather than entering the date using input dialog boxes...BUT, I figured it out...that's for responding though!
Apr 18 '07 #4
cnorthcutt
1 New Member
I have the same problem also. What did you come up with?

Hi, I am working on a java program for my class where I have to rewrite a code that checks whether the input is a palindrom by passing the string as a command-line argument.
Here is the code that I have to rewrite. PLEASE HELP!!
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane;
  2.  
  3. public class CheckPalindrome
  4. {
  5.     public static void main(String [] args)
  6.     {
  7.         String s = JOptionPane.showInputDialog("Enter a string");
  8.  
  9.         String output = "";
  10.  
  11.         if(isPalindrome(s))
  12.             output = s + " is a palindrome.";
  13.         else
  14.             output = s + " is not a palindrome.";
  15.  
  16.         JOptionPane.showMessageDialog(null, output);
  17.     }
  18.  
  19.     public static boolean isPalindrome(String s)
  20.     {
  21.         int low = 0;
  22.  
  23.         int high = s.length() - 1;
  24.  
  25.         while(low < high)
  26.         {
  27.             if(s.charAt(low) != s,charAt(high))
  28.                 return false;
  29.  
  30.             low++;
  31.             high--;
  32.         }
  33.         return true;
  34.     }
  35. }
  36.  
Oct 8 '07 #5
dmjpro
2,476 Top Contributor
Hi, I am working on a java program for my class where I have to rewrite a code that checks whether the input is a palindrom by passing the string as a command-line argument.
Here is the code that I have to rewrite. PLEASE HELP!!
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane;
  2.  
  3. public class CheckPalindrome
  4. {
  5.     public static void main(String [] args)
  6.     {
  7.         String s = JOptionPane.showInputDialog("Enter a string");
  8.  
  9.         String output = "";
  10.  
  11.         if(isPalindrome(s))
  12.             output = s + " is a palindrome.";
  13.         else
  14.             output = s + " is not a palindrome.";
  15.  
  16.         JOptionPane.showMessageDialog(null, output);
  17.     }
  18.  
  19.     public static boolean isPalindrome(String s)
  20.     {
  21.         int low = 0;
  22.  
  23.         int high = s.length() - 1;
  24.  
  25.         while(low < high)
  26.         {
  27.             if(s.charAt(low) != s,charAt(high))
  28.                 return false;
  29.  
  30.             low++;
  31.             high--;
  32.         }
  33.         return true;
  34.     }
  35. }
  36.  
So you don't want to use Swing :-)
So simply do it .............

Expand|Select|Wrap|Line Numbers
  1. //String s = JOptionPane.showInputDialog("Enter a string");
  2. //now change this line to..............
  3. String s = args[0];
  4.  
If you want to check whether user passes the arguments then you can also do it..

Expand|Select|Wrap|Line Numbers
  1. if(args.length==0) return;
  2.  
Enjoy the code.

Debasis Jana
Oct 9 '07 #6
r035198x
13,262 MVP
I have the same problem also. What did you come up with?
Why don't you post what you've done so far?
Oct 9 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2589
by: Hari | last post by:
can i have command line arguments in VS.NET applicatio? if yes how? Can i have some code snippets of the above functionality? I know we can acjieve this in console application form command...
8
5451
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
25
3287
by: David Bernier | last post by:
I'd like to pass on the command line two filenames. As for example: my_executable filename_1 filename_2 I haven't done any C programming with command line arguments so far. I'm familiar...
5
1882
by: jcrouse | last post by:
I have the following code: Dim MyStartupArguments() As String MyStartupArguments = System.Environment.GetCommandLineArgs UBound(MyStartupArguments) RomName =...
1
7878
by: amirmira | last post by:
I would like to set command line arguments to a service at install time. I need to do this because I need to get information from different registry locations depending on my command line argument....
1
2436
by: Rune Jacobsen | last post by:
Hi, I've been trying to figure this one out, but my experience just doesn't have what it takes... :| I am writing an application that reads an XML file and displays the contents in various...
9
2340
by: santosh | last post by:
Hello all, I've put together a small program to count the number of characters and 'words' in a text file. The minimum length of a word, (in terms of no. of characters), as well as word...
1
3694
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
40
2688
by: raphfrk | last post by:
I have a program which reads in 3 filenames from the command line prog filename1 filename2 filename3 However, it doesn't work when one of the filenames has spaces in it (due to a directory...
3
1816
by: Eric_Dexter | last post by:
I am trying to take some data in file that looks like this command colnum_1 columnum_2 and look for the command and then cange the value in the collum(word) number indicated. I am under...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.