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!! -
import javax.swing.JOptionPane;
-
-
public class CheckPalindrome
-
{
-
public static void main(String [] args)
-
{
-
String s = JOptionPane.showInputDialog("Enter a string");
-
-
String output = "";
-
-
if(isPalindrome(s))
-
output = s + " is a palindrome.";
-
else
-
output = s + " is not a palindrome.";
-
-
JOptionPane.showMessageDialog(null, output);
-
}
-
-
public static boolean isPalindrome(String s)
-
{
-
int low = 0;
-
-
int high = s.length() - 1;
-
-
while(low < high)
-
{
-
if(s.charAt(low) != s,charAt(high))
-
return false;
-
-
low++;
-
high--;
-
}
-
return true;
-
}
-
}
-
6 4005
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???
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!! -
import javax.swing.JOptionPane;
-
-
public class CheckPalindrome
-
{
-
public static void main(String [] args)
-
{
-
String s = JOptionPane.showInputDialog("Enter a string");
-
-
String output = "";
-
-
if(isPalindrome(s))
-
output = s + " is a palindrome.";
-
else
-
output = s + " is not a palindrome.";
-
-
JOptionPane.showMessageDialog(null, output);
-
}
-
-
public static boolean isPalindrome(String s)
-
{
-
int low = 0;
-
-
int high = s.length() - 1;
-
-
while(low < high)
-
{
-
if(s.charAt(low) != s,charAt(high))
-
return false;
-
-
low++;
-
high--;
-
}
-
return true;
-
}
-
}
-
Could you tell us what specific problem you have with this.
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!
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!! -
import javax.swing.JOptionPane;
-
-
public class CheckPalindrome
-
{
-
public static void main(String [] args)
-
{
-
String s = JOptionPane.showInputDialog("Enter a string");
-
-
String output = "";
-
-
if(isPalindrome(s))
-
output = s + " is a palindrome.";
-
else
-
output = s + " is not a palindrome.";
-
-
JOptionPane.showMessageDialog(null, output);
-
}
-
-
public static boolean isPalindrome(String s)
-
{
-
int low = 0;
-
-
int high = s.length() - 1;
-
-
while(low < high)
-
{
-
if(s.charAt(low) != s,charAt(high))
-
return false;
-
-
low++;
-
high--;
-
}
-
return true;
-
}
-
}
-
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!! -
import javax.swing.JOptionPane;
-
-
public class CheckPalindrome
-
{
-
public static void main(String [] args)
-
{
-
String s = JOptionPane.showInputDialog("Enter a string");
-
-
String output = "";
-
-
if(isPalindrome(s))
-
output = s + " is a palindrome.";
-
else
-
output = s + " is not a palindrome.";
-
-
JOptionPane.showMessageDialog(null, output);
-
}
-
-
public static boolean isPalindrome(String s)
-
{
-
int low = 0;
-
-
int high = s.length() - 1;
-
-
while(low < high)
-
{
-
if(s.charAt(low) != s,charAt(high))
-
return false;
-
-
low++;
-
high--;
-
}
-
return true;
-
}
-
}
-
So you don't want to use Swing :-)
So simply do it ............. -
//String s = JOptionPane.showInputDialog("Enter a string");
-
//now change this line to..............
-
String s = args[0];
-
If you want to check whether user passes the arguments then you can also do it.. -
if(args.length==0) return;
-
Enjoy the code.
Debasis Jana
I have the same problem also. What did you come up with?
Why don't you post what you've done so far?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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
|
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.
|
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)
|
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...
| |
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,...
|
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...
|
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...
|
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
|
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
|
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...
| |
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...
|
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...
|
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,...
|
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...
|
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();...
|
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...
| |
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
|
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...
| |