Hi sorry about asking so many questions.....and yes i have been searching on the internet, but anyways i am getting to start checking the array words with its chars and whatnot, but i dont know if will work i am confused where to put the array of words i have and in what method and just wondering if my code will eventually even work? any help will be helpfull critique as much as you want thank you

Recommended Answers

All 11 Replies

Hi there, just curious, why do you want to use a char array and not a String object? Possibly using a char array would save memory or be faster, but if you used strings, then there are methods that allow you to easily search the string for any substring. In particular (taken from the Java Docs):

indexOf(int ch, int fromIndex) Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.

I haven't taken a good look at your code, but declaring and instantiating the String array object, you must separate each element with a comma like so:

String wordList[] = {
		"BEAU",
		"SHERLOCK",
		"ROBIN",
                ...
                "HARRAL",
		"CAMPOS"
                };

Notice that the is no comma for the last element and that there is a semicolon at the end of the declaration. The semicolon is required. Perhaps try asking a more specific question. One should always have an algorithm in mind when one is programming, perhaps share this algorithm with us and we can assist you from there... :icon_biggrin:

And please include the code in post with [code] [/code] tags. Many people, myself included, do not want to mess with attachments to glance at your code.

ok sorry about the code part....noobie please forgive and as the string object i havent really gone over it in class and i dont know how to use it? so basically its over my head right now lol......as for the strings i understand thee wordList but don't know where to put it?

I have a method for checking the buttons pushed and if it should be put in wrong letters right letters etc? should it go in there?

and as you stated i dont know how to check the array strings i have with the chars so if the user guesses a letter it is right? Basically what i have below is my words and a random gen to pick a random word and i need help with how to check chars and what method to put it in.....once i get that i can show you my for and what not to check the chars to see if it will work thanks for anything if anything is confusing just ask and sorry i am a noobie

    String wordList[] = {
        "BEAU",
        "SHERLOCK",
        "ROBIN",
        "LUKE",
        "AMY",
        "JASON",
        "AUGUSTIN",
        "FAITH",
        "BRANDON",
        "JENNIFER",
        "JAVA",
        "GREENE",
        "MORTON",
        "BLODGETT",
        "HOLMES",
        "PAPWORTH",
        "PETERSEN",
        "CHAMBERS",
        "HARRAL",
        "CAMPOS",}; 

     char array[]=wordList[0].toCharArray();
     char array1[]=wordList[1].toCharArray();
     char array2[]=wordList[2].toCharArray();
     char array3[]=wordList[3].toCharArray();
     char array4[]=wordList[4].toCharArray();
     char array5[]=wordList[5].toCharArray();
     char array6[]=wordList[6].toCharArray();
     char array7[]=wordList[7].toCharArray();
     char array8[]=wordList[8].toCharArray();
     char array9[]=wordList[9].toCharArray();
     char array10[]=wordList[10].toCharArray();
     char array11[]=wordList[11].toCharArray();
     char array12[]=wordList[12].toCharArray();
     char array13[]=wordList[13].toCharArray();
     char array14[]=wordList[14].toCharArray();
     char array15[]=wordList[15].toCharArray();
     char array16[]=wordList[16].toCharArray();
     char array17[]=wordList[17].toCharArray();
     char array18[]=wordList[18].toCharArray();
     char array19[]=wordList[19].toCharArray();
     char array20[]=wordList[20].toCharArray();

    String randomString=wordList[(int)(wordList.length*Math.random())]; 

    public void actionEvent(ActionListener evt)
    {

    }

Are you retarded....?

Please post up the code, quit being lazy. Maybe if you make it easier for us to help, then maybe we will share our knowledge with you, maybe. IMHO your trying to hard.

I hate you sherlock....
ps this is to warriors16

Interesting.

To check the array that is made of Strings, you just go

if(wordlist[1] = "whatever the name is")

Thats how you check the array of Strings you made.
Your code is very complicated.

char array[]=wordList[0].toCharArray();

What does that above line mean? Your creating an Array called array and it is of char values and of no size. Then you are saying it is equal to the value of wordList[0]. Why are you doing this? It sounds kind of redundent don't you think?

Interesting.

To check the array that is made of Strings, you just go

if(wordlist[1] = "whatever the name is")

Not quite, you never want to use the assignment operator for a boolean expression since it will always be true if the value stored isn't null.

You may want to use syntax such as--

if(wordlist[1].equalsIgnoreCase("whatever the name is"))


Thats how you check the array of Strings you made.
Your code is very complicated.

char array[]=wordList[0].toCharArray();

What does that above line mean? Your creating an Array called array and it is of char values and of no size. Then you are saying it is equal to the value of wordList[0]. Why are you doing this? It sounds kind of redundent don't you think?

Actually toCharArray() returns an array of the size of the amount of characters in the String value (not including the null terminator).

So if wordList[0] contains the String "Value" then toCharArray of that would be a char array of size 5 from indices 0-4.

The declaration char array[] means that the variable array is of type char[]. Size is later listed either directly or indirectly.

You don't need to declare char arrays for every value in the word list. You have a single word chosen randomly from that list and you only need to worry about the characters in that word

char[] characters = randomString.toCharArray();

or you can dispense with the array and check any character with

randomString.charAt(0)

for any position 0 to length-1.

commented: A relentless helper!! +3

Are you retarded....?

Please post up the code, quit being lazy. Maybe if you make it easier for us to help, then maybe we will share our knowledge with you, maybe. IMHO your trying to hard.

Overly harsh, and unnecessary, in my opinion. The OP posted code and made a slight error with the code tags. He's a noob, so cut him some slack. You made a mistake in your post, which Alex Edwards pointed out, and nobody insulted you because of it.

Interesting.

To check the array that is made of Strings, you just go

if(wordlist[1] = "whatever the name is")

Thats how you check the array of Strings you made.
Your code is very complicated.

char array[]=wordList[0].toCharArray();

What does that above line mean? Your creating an Array called array and it is of char values and of no size. Then you are saying it is equal to the value of wordList[0]. Why are you doing this? It sounds kind of redundent don't you think?

Actually warrior16's mistake was far more serious and shows an incredible lack of java knowledge. I never post a solution that I haven't tried myself so I will know that it will work.

if(wordlist[1] = "whatever the name is")

You NEVER use '==' to compare Strings (you used '=' but let's say that it was an honest mistake).
That piece of code and your next question about the array thing shows that you have no clue about java and you shouldn't even post your so-called solutions, and YOU were the lazy one, not bothering to check the API for the toCharArray() method

PS: Don't let this guy get you Futbol10

Thanks for all your help guys and as for you warrior16, whatever man im sorry im not as smart as you at this java programming......and thanks guys i have finished my program and it works awesome thanks for all the help:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.