aspose file tools*
The moose likes Java in General and the fly likes Where did I go wrong? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Where did I go wrong?" Watch "Where did I go wrong?" New topic
Author

Where did I go wrong?

Jason Batchelder
Ranch Hand

Joined: Jan 27, 2005
Posts: 37
I think I'm close but somethings wrong. Could someone help me out? Here's the code. I'm pretty sure that it's close.

import java.util.*;

public class CheckPalindrome
{
public static void main(String args[])
{
String input;
System.out.println("Hello and welcome to the palindrome program!");
System.out.println();
System.out.println("Enter quit to end the program.");

do
{
Scanner keyboard=new Scanner(System.in);
System.out.println("Enter a sentence and I will check it:");
phrase=keyboard.next();//recording the string
palindrome(input);//checking
}
while (!input.equals("quit"));
}
String cleanSentence = clean(args[0].toCharArray());

if (isPalindrome(new String(cleanSentence))) {
System.out.println("Is a palindrome");
} else {
System.out.println("Is NOT a palindrome");


//
// returns true if word is a palindrome
//
private static boolean isPalindrome(String phrase) {
return phrase.equalsIgnoreCase((new StringBuffer(phrase)).reverse().toString().toUpperCase());

}
//
// removes all non letters from the sentence
//
private static String clean(char [] palindrome) {
String sentence = "";
for (int i = 0; i < palindrome.length; i++) {
if (Character.isLetter(palindrome[i])) {
sentence += palindrome[i];
}
}
return sentence;
}
}

Thanks in advance.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10905
    
  12

Jason,

What specifically is your question? what is the code doing/not doing that you expect it to?

People here love to help, but you have to give us a little guidence as to how to help you.

Also, please learn to use the code tags. it is MUCH easier to read your code if you surround your code with the proper tags as it will preserve indentation. There are a bunch of buttons below where you enter your posts... click the one called "code" and you'll see the tags appear at the end of what you've typed. just paste your formatted code between the tags, and life will be much easier for everyone...

thanks!!!


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
John Dell'Oso
Ranch Hand

Joined: Apr 08, 2004
Posts: 130
Jason,

First up, when posting code, please use the UBB Code function so that your code shows as formatted code - you know indents and the like.

As far as what you have posted is concerned, the reference variable "phrase" has not been declared with a type (I assume it would be of type String). You also make a reference to a method called "palindrome(....)" and this method is no where to be found.

Regards,
JD
[ March 18, 2005: Message edited by: John Dell'Oso ]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10905
    
  12

i also think you have code outside of a method... you have a do-while loop in your main..

after the " while (!input.equals("quit"));" line, you have a closing brace. i think this closes your main() method, but then you have more code. you can't do this.

i only say i'm not sure because without indenting, it's hard to read. plus, it's early, and i make bad assumptions about code before 9am.
Jason Batchelder
Ranch Hand

Joined: Jan 27, 2005
Posts: 37
Sorry about that! This was the first time I ever posted code to the board so I wasn't sure how to go about it. (Copying and pasting has got me in trouble before and it probably will again! ) I'll do better next time, promise!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Where did I go wrong?
 
Similar Threads
Palindrome
Please help me on this palindrome program
palindrome not very proficient...
Palindrome example
palindrome program