The ‘X Character Finder’ Crapfest

So, Java, huh?

It’s not so bad, actually.

As a first language, Java is okay – especially when it is taught right (inside joke there).

Anyway, hot on the heels (somewhat cold, actually), of the Windows Shutdown Crapfest, comes the X Character Finder crapfest, courtesy of yours truly.

First, a little background to this – at Uni I’m doing a subject called programming and problem solving. It involves Java.

Our first assignment was to calculate some variable. Or something. Anyway – one of the things we had to do was find out if the user’s name had the ‘x’ character in it – in either upper or lower case.

This is what I managed to come up with – I’ve commented the code so you understand what it does. I’ve also used Pastie to embed the code, because this is the one time WordPress has failed me. Right, everything seems to be failing hard on me tonight, so I’ve just linked the Pastie… 🙁

If you don’t really get what’s going on, I wouldn’t worry. Here’s the english explanation: Get a username. Count the letters in that username. Look at the first character – if it’s an X or an x, then we have an x in the username. If it’s not an X or an x, then we look at the next character in the username, and perform the same “Is it an X or and x check” again. We keep doing this until we either find an X, or we’ve run out of characters in the username. If you just want to know why this is the X Character Finder crapfest, well, it’s just because I’m re-inventing the wheel here, man – there’s a heaps easier way to find if a particular word/string has a particular character in it, and that’s via use of methods.

The real code that I submitted looks like this. Thanks again to Pastie. 🙂

See? Much easier.

This was the X Character Finder Crapfest, brought to you by Benny Ling.

Comments below.

Tags: , , , , , , , , , , , , ,