Difference between revisions of "Palindromes"
Line 37: | Line 37: | ||
Second, take a break if you are stuck. If you are mentally tired and cannot figure a way out, take a break. Otherwise, you will even mess up with the parts that were actually correct. This will make you extremely stressed out, and you will most likely <i>NOT</i> finish your assignment.<br> | Second, take a break if you are stuck. If you are mentally tired and cannot figure a way out, take a break. Otherwise, you will even mess up with the parts that were actually correct. This will make you extremely stressed out, and you will most likely <i>NOT</i> finish your assignment.<br> | ||
Third, do not look up solutions on internet. If you are in first year and barely know few things, you will never understand solutions on internet. There are tons of people who write programs using different techniques than our university teaches. You will simply waste your time on looking for solutions. <br> | Third, do not look up solutions on internet. If you are in first year and barely know few things, you will never understand solutions on internet. There are tons of people who write programs using different techniques than our university teaches. You will simply waste your time on looking for solutions. <br> | ||
− | Fourth, start assignments ahead of time. I used to start assignments a day before, and I had many troubles finishing them properly. Even if the first year computer science assignments are easy, they still take up some time. Besides, if you start taking second year computer science courses, you will NEVER finish an programming assignments in one day. | + | Fourth, start assignments ahead of time. I used to start assignments a day before, and I had many troubles finishing them properly. Even if the first year computer science assignments are easy, they still take up some time. Besides, if you start taking second year computer science courses, you will NEVER finish an programming assignments in one day.<br> |
These tips always helped me doing assignments. However, these are very general tips for doing assignments. As you experience more and more in programming, you will find out more tips that are more specific to your case. | These tips always helped me doing assignments. However, these are very general tips for doing assignments. As you experience more and more in programming, you will find out more tips that are more specific to your case. | ||
Revision as of 19:08, 10 April 2010
Back to the Program-A-Day homepage
ProblemThis question will help you practice with string methods and for loops.
public class Palindrome { public static void main(String[] args) { String testWord1 = "Arewenotdrawnonward,wefew,drawnonwardtonewera" String testWord2 = "Murderforajarofredrum" // Your code goes here } } |
By students..Before taking Comp 1010 course, I had never had any programming experiences. I did not know much, and I have had many problems with assignments. I'd like to give you some tips that helped me with doing programming assignments. | |
---|---|---|
SolutionFirst of all, you will need to declare two string objects to store the reversed words. String reverse1 = "" String reverse2 = ""
str.length();
for(int i = 0; i < testWord1.length(); i++) { }
reverse1 = get the letters of the str by charAt(i) + reverse1
for(int i = testWord2.length()-1; i >= 0; i--) { }
reverse2 = reverse2 + letters of the str by charAt(i) str = "abcde" Once you have the two words reversed, you will need a condition statement to check if they are palindromes.
if testWord == reversedTestWord { Then, print out success } else { print out reservedTestWord }
testWord.equals(reversedTestWord).
str.equalsIgnoreCase()
| ||
Code |