A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
arrays?
Jeremy Swain
Greenhorn
Joined: Nov 21, 2005
Posts: 3
posted
Nov 21, 2005 04:44:00
0
hello all. i am working on a program that decides if a word or a sentence is a palindrome. this is my first time using JOption. here is my code:
import javax.swing.*; public class swain1Palindrome { public static void main (String[ ] args) { String inputSentence; int leftCharInputSentence, rightCharInputSentence; inputSentence = JOptionPane.showInputDialog(null, "Enter a sentence or word: "); getDecision(); getResponce(); private void getDecision() { rightCharInputSentence = inputSentence.length() - 1; leftCharInputSentence = 0; while ((inputSentence.charAt(leftCharInputSentence) == inputSentence.charAt(rightCharInputSentence)) && (leftCharInputSentence < rightCharInputSentence)) { leftCharInputSentence++; rightCharInputSentence--; } } private void getResponce() { if (leftCharInputSentence < rightCharInputSentence) { JOptionPane.showMessageDialog(null, inputSentence + notPalindrome); } else { JOptionPane.showMessageDialog(null, inputSentence + isPalindrome); } } public void aPalindrome(String isPalindrome) { isPalindrome = " is a Palindrome."; } public void notPalindrome(String notAPalindrome) { notAPalindrome = " is NOT a Palindrome"; } } }
Jeremy Swain
Greenhorn
Joined: Nov 21, 2005
Posts: 3
posted
Nov 21, 2005 04:48:00
0
sorry, i accidently added this twice. please disregard this post.
Stuart Ash
Ranch Hand
Joined: Oct 07, 2005
Posts: 637
posted
Nov 21, 2005 06:21:00
0
Why are you mixing algorithm and presentation??
Code two classes:
PalindromeFinder and PalindromeUI.
Implement the logic in the finder, the UI gets the input from the user.
ASCII silly question, Get a silly ANSI.
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: arrays?
Similar Threads
palindrome not very proficient...
Palindrome
Palindrome example
how to check whether a word is a palindrome
arrays?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter