Results 1 to 1 of 1
  1. #1
    maddogg2222 is offline Member
    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Default hang man problem

    Sorry, I just got it to work.. Thanks anyways..

    Hello, i'm currently working on this hangman project and I cant seem to get it to work. basiacally the main thing that its doing is its only testing the last charactor in the string that its using as the hidden word ive worked for a few days on this and i cant seem to fix it.. can any one see what im doing wrong here?

    Java Code:
    public class hangMan
    {
    public static void main(String[] args)
    {
        boolean stillPlaying = true;
        String word = "hat";
        String wordAsBlanks[] = new String [word.length()];
        CinReader reader = new CinReader();
        do{
        for(int i=0;i<word.length();i++)
        {
    	System.out.print(wordAsBlanks[i] = " - ");
        }//end for
    	
    	System.out.println("Guess::");
    
    	String userGuess = reader.readString();
    
    	for(int j = 0;j<word.length();j++)
    	{
    	
    	if(userGuess.equals(word.substring(j)))
    	{
    	   System.out.println("Correct");
    	    
    	    wordAsBlanks[j] = userGuess;
    	    break;
    	   
    	} 
    	
        }//end for
        }//end do
        while(stillPlaying);
    }//end main
    }
    Thanks in advance!

    Sorry, I forgot to get rid of that for loop using k as an increasment operator around System.out.println("Guess::"); I just removed it.
    Last edited by maddogg2222; 03-05-2013 at 11:44 PM. Reason: solved

Similar Threads

  1. code gets hang
    By rungtashubham in forum AWT / Swing
    Replies: 4
    Last Post: 03-22-2012, 08:40 PM
  2. What type of hang? and how to fix?
    By joshbrigade in forum New To Java
    Replies: 2
    Last Post: 11-06-2009, 11:40 PM
  3. Read XML from Internet Hang!
    By yupingliew in forum Networking
    Replies: 0
    Last Post: 10-22-2009, 06:56 AM
  4. Applet hang
    By Worlock in forum New To Java
    Replies: 2
    Last Post: 08-10-2009, 07:43 AM
  5. Web application hang without comm.jar
    By chankokchern in forum Java Applets
    Replies: 0
    Last Post: 12-16-2008, 01:38 PM

Tags for this Thread

Posting Permissions

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