Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Wordguess program wouldn't run

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Wordguess program wouldn't run

    This is my wordguess program but it wouldn't run. THis is similar to the hangman game on iphone
    import java.util.Random;
    import java.util.Scanner;
     
    public class Wordguess123 {
    public static String replaceCharAt(String s, int pos, char c) {
        return s.substring(0,pos) + c + s.substring(pos+1);
     }
     public static void main(String[] args){
            Scanner Jerry = new Scanner(System.in);
            Random Rong = new Random(10);
            String word;
            boolean guess = true;
            int i = 0;
            String win = "YOUWIN!!!!";
            System.out.println("This is Jerry Rong's wordguess game!");
     
            switch (Rong.nextInt()) {
     
                case 1: word = "PROPORTION";
                break;
                case 2: word = "DISTANCE";
                break;
                case 3: word = "MOMENTUM";
                break;
                case 4: word = "HELLO";
                break;
                case 5: word = "GRAPHIC";
                break;
                case 6: word = "ACCELERATION";
                break;
                case 7: word = "ENERGY";
                break;
                case 8: word = "NINJA";
                break;
                case 9: word = "FINALS";
                break;
                default: word = "CHRISTMAS";
                break;
         }
     
         int length = word.length();
         String blank = null;
         for (int h = 0; h < length; h++)
         {  blank = "_" + " ";}
     
         System.out.println(blank);
         String PeoplesGuess = blank;
     
         do {
          i++;
          String letter = in.next();
         letter = letter.toUpperCase();
         if (letter =! "!") {
     
            for (int k = 0; k < length; k++){
     
                        if (letter.charAt(0) == word.charAt(k)) {
                            current = replaceCharAt(current, k, letter.charAt(0));
                        }
     
                    }
     
            if (current.equals(word)) {System.out.println("You win!!");     } 
            System.out.println ("you used" + i + "guesses ");
            System.out.println ("The secret word is" + word  );
                }
     
         else 
         {
             System.out.println("Guess the word in uppercase.");
             String guessedword = in.next();
             guess = false;
             if (guessedword.equals(word)) {System.out.println(win));}
             else System.out.println("Haha you lose");
             System.out.println ("you used" + i + "guesses ");
            System.out.println ("The secret word is" + word  );
     
     
            }
     
     
     
     
    }
    while ( i < 27 && guess = true);


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Wordguess program wouldn't run

    Is there any error or exception thrown by the program? If yes, what? Elaborate your problem description.

Similar Threads

  1. Help with class program!!! STUCK! Program not doing what I Want!!!
    By sketch_flygirl in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2011, 07:29 AM