The Artima Developer Community
Sponsored Link

Java Answers Forum
Help me!!!!

3 replies on 1 page. Most recent reply: Oct 4, 2003 5:51 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
kexiang

Posts: 1
Nickname: keny
Registered: Oct, 2003

Help me!!!! Posted: Oct 4, 2003 11:06 AM
Reply to this message Reply
Advertisement
I am a beginner of Java. I have difficulty writing a Java program.Could somebody help me? Please try to use a sample method. Thank you!
Here is the instruction:

Write a program that will evaluate a single word or string of digits to determine whether or not it is a palindrome. If the input value was “radar”, use System.out.println() to output the statement:

radar is a palindrome

*** end of program ***


David

Posts: 150
Nickname: archangel
Registered: Jul, 2003

Re: Help me!!!! Posted: Oct 4, 2003 11:26 AM
Reply to this message Reply
Nobody here will do your homework for you.

However, we are more than happy to help you solve any problems you're having.

How do you think you should solve this problem?

What code do you have at the moment? Post it.

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: Help me!!!! Posted: Oct 4, 2003 2:56 PM
Reply to this message Reply
I would imagine that you would want two variables: one with the original word and one with the original word reversed. Then you could just see if one variable equals the other.

Take a look at the String-related classes; for example, StringBuffer.

If you need any more hints, just post back.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Help me!!!! Posted: Oct 4, 2003 5:51 PM
Reply to this message Reply
Sheesh, I think this homework assignment has been rehashed a thousand times here, but just in case you are too lazy to search the forum (which is apparently the case), here is the solution (it compiles fine and you can turn it in as-is):
public class P{public static boolean _(String __){for(int ___=0;___<__
.length()/2;___++)if(__.charAt(___)!=__.charAt(__.length()-___-1))
return false;return true;}public static void main(String[] __){for(int
___=0;___< __.length;___++)System.out.println("\""+__[___]+"\" is "+
(_(__[___])?"":"not ")+"a palindrome.");}}

Flat View: This topic has 3 replies on 1 page
Topic: how to read thread dumps Previous Topic   Next Topic Topic: Need math script help

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use