473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

program does not display output

Hi everyone i'm newbie here in bytes and a newbie in programing i need your help! can you correct my program when my program compile its say Process completed. but when i put a Word and Run my program does not show an output what is the problem?

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2.  
  3. public class Palindrome
  4. {
  5.     public static void main(String[] args) 
  6.     {
  7.         String A;
  8.         int i,palindrome=1;
  9.         A=JOptionPane.showInputDialog(null,"Enter a Word");
  10.  
  11.         for(i=0;i<A.length()/2;++i)
  12.         {
  13.             if(A.charAt(i)!=A.charAt(A.length())-i-1)
  14.             {
  15.                 palindrome=0;break;
  16.             }
  17.             if(palindrome==1)
  18.             System.out.println("The Word "+A+" is a Palindrome"); 
  19.             else
  20.             System.out.println("The Word "+A+" is not a Palindrome");
  21.         }
  22.     }
  23. }
Nov 30 '09 #1
2 2025
pbrockway2
151 Expert 100+
Do you get any runtime error message? These are very helpful so, if you do, post the entire message (including the stack trace which shows where the error occurred) and also indicate which line of your code it is referring to.
Nov 30 '09 #2
mrjohn
32
Two bugs.

On line 15 (Your if-statement where you check to see if characters are the same), you have A.charAt(A.length())-i-1). You need to move the -i-1 part into the charAt() method, or you'll have a null pointer exception. So it'd be A.charAt(A.length()-i-1)).

The other bug is that you've got your if statement that determines which output to print inside your for-loop. Since your loop exits if it finds a mismatch, it'll skip this code. To fix it, just move the if-statement out of the for-loop like so:
Expand|Select|Wrap|Line Numbers
  1. for(i=0;i<A.length()/2;++i)
  2.         {
  3.             if(A.charAt(i)!=A.charAt(A.length()-i-1))//Error1
  4.             {
  5.                 palindrome=0;break;
  6.             }
  7.         }
  8.         if(palindrome==1)
  9.             System.out.println("The Word "+A+" is a Palindrome");
  10.         else
  11.             System.out.println("The Word "+A+" is not a Palindrome");
Dec 1 '09 #3

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

Similar topics

22
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
6
by: tigrfire | last post by:
I've been working on a program to try and play a game of Craps, based on a version I found elsewhere - I didn't code the original, but I added a few things such as a balance and wager system. I'm...
55
by: Dev | last post by:
Hello Folks, I had faced this objective in one of my aptitude exams, that "What could be the smallest "C" program? And, as we know, smallest program means, it should execute single statement,...
109
by: zaidalin79 | last post by:
I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the...
2
by: zaidalin79 | last post by:
Here is my Inventory program for my Java class.... //Inventory.java //Class created to store item information for Inventory purposes //Created November 15, 2006 //Modified November 29, 2006...
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
3
by: baden | last post by:
Hi, I don't know why the final output does not work right. It does not display anything and I don't know why. import javax.swing.*; public class lab5 { public static...
9
by: Hypnotik | last post by:
Ok, so I've finished the "library" problem. The program takes in input and sorts the information. However the program crashes if I enter an authors name beginning with the letter z. Also if the book...
7
by: Jwe | last post by:
Hi, I've written a program which has both a command line interface and Windows form interface, however it isn't quite working correctly. When run from command line with no arguments it should...
13
by: Liang Chen | last post by:
Hope you all had a nice weekend. I have a question that I hope someone can help me out. I want to run a Python program that uses Tkinter for the user interface (GUI). The program allows me to type...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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
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...

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.