Hi I'm am new to Java. How do I take a String argument and return a boolean value? :confused:
Printable View
Hi I'm am new to Java. How do I take a String argument and return a boolean value? :confused:
Code Java:public boolean methodName(String param1) { // some logic/code here return true; // or return false; }
how do I post my code?
Code Java: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; } } }
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:
Code Java:// 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
Code :if (s.charAt (locationFromStart) == s.charAt(s.length()-1-locationFromStart))
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