Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By kjkrum

Thread: Need help with a java problem

  1. #1
    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

    Default Need help with a java problem

    hey guys, im new to java and i need to submit an assignment for school..
    i need to create a hangman program with minimum of 4 methods, must use array and the random util..
    so heres the problem, i need to create an array containing the hidden words and using the random util, the computer automatically picks the hidden word in the array..pls pls..i really dun know where to start..

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Need help with a java problem

    Have you written any code? Nobody's going to do your homework for you, but if you show us what you've done, we can tell you what to do next.
    DarrylBurke likes this.
    Get in the habit of using standard Java naming conventions!

  3. #3
    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

    Default Re: Need help with a java problem

    is this the right way of creating an array? i think ill start with the hidden words..


    public class FinalHangman {
    public static void main(String[] args){
    System.out.println("Welcome to Hangman V 0.0");
    HiddenWord();
    }
    public static void HiddenWord(){
    String[] HiddenWords;
    HiddenWords = new String[10];
    HiddenWords[0] = driedfish;
    HiddenWords[1] = shrimp;
    HiddenWords[2] = nosebleed;
    HiddenWords[3] = epistaxis;
    HiddenWords[4] = cheese;
    HiddenWords[5] = banana;
    HiddenWords[6] = word;
    HiddenWords[7] = hiddenword;
    HiddenWords[8] = java;
    HiddenWords[9] = program;

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Need help with a java problem

    Well, you are on the right track to creating and initializing an array. Except those aren't proper String literals you're assigning, and that's not a complete program because it's missing a few closing brackets. Another problem is that you're creating your array as a local variable inside a method that returns void. As such, it is not accessible to the rest of the program. One possible solution: change the method to return String[], and return the array you created. Then assign the return value to a variable.

    BTW, when posting code, please surround it with [ code] [ /code] tags (without the spaces).
    Get in the habit of using standard Java naming conventions!

  5. #5
    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

    Default Re: Need help with a java problem

    thanks finally got a working array, now, how do i randomly pick an element from my array of 10 elements?

  6. #6
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Need help with a java problem

    Have a look at Random (Java Platform SE 6).
    Get in the habit of using standard Java naming conventions!

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Need help with a java problem

    Also go through the Forum Rules -- particularly the third paragraph, and
    Guide For New Members
    BB Code List - Java Programming Forum

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Problem with java
    By kilian29870 in forum New To Java
    Replies: 1
    Last Post: 07-03-2012, 05:33 AM
  2. Replies: 4
    Last Post: 03-16-2012, 12:29 PM
  3. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 04:43 AM
  4. Java url problem
    By sharifiit in forum Networking
    Replies: 0
    Last Post: 04-30-2011, 08:52 PM
  5. Problem Display Jmenubar Java Se6 u23 versus Java SE6 u22
    By Ravanelly in forum Advanced Java
    Replies: 0
    Last Post: 01-07-2011, 10:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •