Right now, I'm having issues making a concise way to enumerate individual letters. Currently, I have a series of while loops that compare my specified string with the string 'abcdefghijklmnopqrstuvwxyz" and then using a counter to determine the position the char falls on the alphabet string.
I realize that Javaranchers aren't allowed to provide free code answers, and frankly, that's not what I'm looking for. I was wondering if you guys had any suggestions in order to make a clearer, more concise way to do this.
Why don't you post what you have now, and we can help you fix it up?
Be sure to use code tags in your post
When you do things right, people won't be sure you've done anything at all.
posted 10 years ago
Here's what I have so far.
The program is made to determine whether or not a word is abecedarian, and works in that sense. However, I am planning on reusing a partial of the code for enumerating the letters, which I can't do right now because that code is a jumbled mess. Basically, I need to parse 'abecedarian' finder code from the letter enumeration code.
Well, here's the thing: "char" is an integral type, and you can compare characters directly as if they were integers. If you assume (or check to make sure) that every character in the word is a lowercase ASCII letter, then you could simply loop over the string and check that each letter is greater than or equal to the previous one (assuming that "abecedarian" means that the letters in the word appear in alphabetical order.) Such a program would be a lot simpler and a lot easier to understand.
Because I'm new-ish to Java, I have yet the learn the concept of arrays and stuff, so that's basically out of my league. However, when 'char' is casted into an 'int' type, what number would that char be? Or does that automatically form a=1, b=2, etc? Also, once the 'char' has been casted, would I be allowed to manipulate that int, and then reform it back into a string?