Results 1 to 7 of 7
Thread: Need help with a java problem
- 09-01-2012, 03:34 AM #1
Member
- Join Date
- Sep 2012
- Posts
- 3
- Rep Power
- 0
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..
- 09-01-2012, 05:43 AM #2
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.
Get in the habit of using standard Java naming conventions!
- 09-01-2012, 08:31 AM #3
Member
- Join Date
- Sep 2012
- Posts
- 3
- Rep Power
- 0
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;
- 09-01-2012, 09:10 AM #4
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!
- 09-02-2012, 06:41 AM #5
Member
- Join Date
- Sep 2012
- Posts
- 3
- Rep Power
- 0
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?
- 09-02-2012, 07:16 AM #6
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!
- 09-02-2012, 08:17 AM #7
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
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Problem with java
By kilian29870 in forum New To JavaReplies: 1Last Post: 07-03-2012, 04:33 AM -
Problem with Java Web Applications and Java in Control Panel
By Abysinian in forum Advanced JavaReplies: 4Last Post: 03-16-2012, 11:29 AM -
Small problem with problem with Java, C++ parse program.
By dragstang86 in forum New To JavaReplies: 4Last Post: 10-30-2011, 03:43 AM -
Java url problem
By sharifiit in forum NetworkingReplies: 0Last Post: 04-30-2011, 07:52 PM -
Problem Display Jmenubar Java Se6 u23 versus Java SE6 u22
By Ravanelly in forum Advanced JavaReplies: 0Last Post: 01-07-2011, 09:36 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks