Monday, November 15, 2010
Love is such a gamble In this great big world
Have I already mentioned, Standing In The Hallway has got to be the weirdest Bangles song ever? Well, almost reaching the standards of Waiting For You, Song For A Good Son, and Return Post. That's not to say that it's not good, it's just very un-Bangly. Urk.
Okay I haven't been posting much here because I was re-teaching myself html and CSS, and also playing around with javabat (now officially renamed codingbat). I miss java! But I can't solve the more difficult ones though. That is, those that include weird stuff like i++/count++ and str.substring all in the same part. It gives me headaches. Boolean operators still have the same attraction as they did back when we started java. For some reason double ampersands look a lot better than just one. And ! is the not operator. || is or! && is and! The only thing I have against java (and CSS too for that matter) is that it reads stuff from top bottom so everything has to be in order or else your code is screwed. Ah well. At least logic problems are easier to solve than array (and advanced string) problems. Because all you use in logic is BOOLEAN! And that means no str.substring(str.length()+2, str.length()-3), count++ or anything like that. Also, both arrays and advanced strings involves char and anything with char kills me. Yup, too awesome right?
Example string code:
public String withoutX2(String str) {
if (str.length() < 1)
return str;
if (str.length() < 2 && str.equals("x"))
return ("");
if (str.length() < 3 && str.equals("xx"))
return ("");
if (str.substring(0,2).equals("xx"))
return (str.substring(2));
if (str.substring(0,1).equals("x"))
return (str.substring(1));
if (str.substring(1,2).equals("x"))
return (str.substring(0,1) + str.substring(2));
else
return str;
}
Example logic code:
public boolean squirrelPlay(int temp, boolean isSummer) {
if ((temp > 59 && temp < 91 && !(isSummer))||(temp > 59 && temp < 101 && (isSummer)))
return true;
else
return false;
}
Yes, I wrote both up. Which one looks simpler? Go figure. Also, logic is much, much simpler to understand and to write, which is essential for not cluttering things, because all you need in return is true or false, unlike strings in which the answer is all about str.substring or str.length() or str. True, I could have used || for the string one but that would have made it even more confusing to read.
Of course, there is a cheat method to solve javabat problems if you're trying to debug. (: You can just run it and see what's the problem, then specifically devote a line to it. Another general rule of thumb: if "The left-hand side of an assignment must be a variable" occurs to you then you change whatever it is you're trying to evauluate into a variable, for example, changing
if (b - a = 10)
return true;
to
int ba = b - a;
if (ba == 10)
return true;
I almost sound like I'm promoting logic for java. With the exception that the example for logic is really simple so maybe it isn't fair after all. :/
Posted at 10:44 PM