This week's book giveaway is in the Design and Architecture forum. We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line! See this thread for details.
Yes, like the subject says: How do i get the index of a character in an array? Help would be appreciated XD
given that this is the array. How would i find the index of 'm' for example?
Greg Brannon wrote:Do you have any guesses? How do you do it in your head or with a piece of paper and a pencil? Can you describe that process and then program it?
well this is my program so far The problem is at line 21, i just don't know the thingie to call the character in the array. This is basically a program that adds up the letter scores of a SCRABBLE word and don't worry about the EasyReader thing
Context is always helpful. There are many ways (I'm not going to count them) to do this problem, but starting with a char[] array may not be at the top of my list. Do you have to use a char[] array? Did you consider just using a String = "abcdefg......z" with its available methods? Or, even better (some would say), a HashMap or other collection that returns a value for an input?
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Greg Brannon wrote:Context is always helpful. There are many ways (I'm not going to count them) to do this problem, but starting with a char[] array may not be at the top of my list. Do you have to use a char[] array? Did you consider just using a String = "abcdefg......z" with its available methods? Or, even better (some would say), a HashMap or other collection that returns a value for an input?
Never mid you are a genius. I don't know why i didn't think of it first
So you'll have to write your own public static int indexOf( char y ) method. How that goes, roughly, is you compare each element of the char[] array at a time to the desired character, y, in a loop that iterates 0 - the length of the array, and when you find a match, you return the value of the loop's index variable.
(That was the kind of answer I was hoping to get to my first question.)
Can you code that?
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Greg Brannon wrote:Context is always helpful. There are many ways (I'm not going to count them) to do this problem, but starting with a char[] array may not be at the top of my list. Do you have to use a char[] array? Did you consider just using a String = "abcdefg......z" with its available methods? Or, even better (some would say), a HashMap or other collection that returns a value for an input?
Never mid you are a genius. I don't know why i didn't think of it first
Not sure what I did to deserve that, but let's part to meet another time as friends. Good luck.
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
So you'll have to write your own public static int indexOf( char y ) method. How that goes, roughly, is you compare each element of the char[] array at a time to the desired character, y, in a loop that iterates 0 - the length of the array, and when you find a match, you return the value of the loop's index variable.
(That was the kind of answer I was hoping to get to my first question.)
I would disagree. There is no need to seek the index of 'q' in that array. Remember that a char is not a letter, but a number, so you can find the index easily by doing arithmetic on the chars.
Water proof donuts! Eat them while reading this tiny ad: