473,657 Members | 2,513 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 4005
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...rath er 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
2603
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 prompt but how can i achieve it in an application in VS.NET? Thank you
8
5463
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 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
25
3315
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 with fopen, ascii mode, binary mode. What I'm doing now is specifying the filenames in the source code.
5
1900
by: jcrouse | last post by:
I have the following code: Dim MyStartupArguments() As String MyStartupArguments = System.Environment.GetCommandLineArgs UBound(MyStartupArguments) RomName = (MyStartupArguments(0).ToString) ParentName = (MyStartupArguments(1).ToString)
1
7893
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. I have to do it this way as the consumer of the service should not be able to change the argument - except by uninstalling and reinstalling the service. I created the service and the service itself works great. However, when I try to install...
1
2446
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 ways to the end user. This works fine. My challenge lies in the fact that these XML files are generated by various (third party) applications. Which application generates them depends on the user, the country they are in, their personal preferences,...
9
2347
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 delimiting characters can be specified on the command line. The default delimiting characters built into the program are space, newline, tab, carriage return, form feed, vertical tab, comma and null. If a 'u' or 'U' is specified as the last command line...
1
3705
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 attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
40
2729
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 name with a space in it) because that filename gets split into 2. I tried
3
1823
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 the impression I need enumerate but I am not sure what to do with it any help would be nice. import sys
0
8413
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5642
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2742
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 we have to send another system
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.