Hi I'm am new to Java. How do I take a String argument and return a boolean value?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hi I'm am new to Java. How do I take a String argument and return a boolean value?
public boolean methodName(String param1) { // some logic/code here return true; // or return false; }
mag12203 (December 18th, 2010)
how do I post my code?
import java.util.*; public class isPalindrome { static Scanner kb = new Scanner(System.in); public static void main(String[] args) { System.out.println("Enter words to check if they are a palindrome: (end to file"); while (kb.hasNext() ) { String s =kb.nextLine(); boolean isPal; System.out.println(isPal + s + "is not a palindrome"); System.out.println("Enter words to check if they are a palindrome: (end to file"); } } public static boolean isPal(String s) { char ch; boolean isPal; for (int x = 0; x < s.length(); x++) { ch = s.charAt(x); if (Character.isPal(s.charAt(x))) { return true; } } }
Last edited by helloworld922; December 18th, 2010 at 07:00 PM.
In the future, please don't start multiple topics for the same question. I've merged these two together.
You can post code by using the highlight tags.
[highlight=Java]
// your code goes here
[/highlight]
This looks like:
// your code goes here
Ok thnaks Do I put the code in the body of this area surrounded by tags. I do not see a separate place for my code.
You paste your code in the body and you write the tags before and after the code.
You can preview your message to see if it turned out ok before you submit.
I don't want to sound rude, but you could have gotten all this by reading the welcoming threads. Put yourself in the place of the moderators: they have to answer questions like this every other day. All that time they could have answered sensible questions. So lesson for the future: next time you post something on a forum, please take some time to read the rules threads first.
Actually I think you rude for first assuming that I did not read the welcoming threads. In fact some of the other members as well respond with rude replys such as calling someone lazy. The moderators have been very respectful but it seems as the members them selves seem to be on some ego trip. People come to this site because most are new to Java and do not want ot feel like we are somehow less intelligent and put in a inferior position because you know more on the subject. Good By Java Forums. I will find another forum IS MORE RESPECTFUL.
We must all remember that the contributors, moderators, and admin to the forums do so in their own free time, without pay, all in the effort to help. At times, this help can be mis-interpreted as rude, but it is simply advice. We all must understand that the format of online forums can at times place this advice out of context, resulting in some statements being interpreted in wrong ways, but the original intent of the contributor is to help.
mag12203, to your problem at hand, the method you posted will not check for a palindrome. You must check each character incrementally in from the beginning and compare that to the character that far in from end of the word to check for equality. So, more along the lines of
if (s.charAt (locationFromStart) == s.charAt(s.length()-1-locationFromStart))
Last edited by copeg; December 19th, 2010 at 03:25 PM.
mag12203 (December 20th, 2010)
I presume you are referring to the often quoted 'How to ask Questions the Smart Way', and its subsection:
How to Answer Questions in a Helpful Way...thanks for mentioning this