Results 1 to 2 of 2

Thread: GameGuess

  1. #1
    Sigmahokies is offline Member
    Join Date
    Apr 2017
    Location
    Richmond, VA
    Posts
    3
    Rep Power
    0

    Default GameGuess

    Hi everyone, I am beginner to Java, I am taking programming project now, I am trying to create computerized player 1 and 2 do guess game by number. I am trying to run the loop in while, but Java get fussy about inside "do" with while loop, can you help me to find what is wrong? Also, while won't do loop if either player 1 or 2 are not equal to random number...can you help? Thank you in advance...

    PHP Code:
    public class GameGuess extends Thread {
    
        int a;
    
        public void Send(int a) {
    
            this.a = a;
        }
     
            do {
        
            int p1 = (int) ((Math.random() + 5) * 10);
            int p2 = (int) ((Math.random() + 5) * 10);
    
            System.out.print("Player 1: " + p1);
            System.out.print("Player 2: " + p2);
    
            if (p1 != a) {
                System.out.print("Player 1 get wrong guess.");
            } else if (p1 == a) {
                System.out.print("The Player 1 wins!");
            } else if (p2 != a) {
                System.out.print("Player 2 get wrong guess");
            } else if (p2 == a) {
                System.out.print("The Player 2 wins!");
            }
        }
        while (p1 != a || p2 != a)
    anyone can help will be appreciate!

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: GameGuess

    There is no use in trying to run code that won't compile. You have numerous syntax errors.

    e.g

    do/while block must be in a method.
    braces {} don't match up
    p1 and p2 declared inside of do/while block.
    no terminating semicolon on while statement.

    And stay away from threads until you get more experience with the basics.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

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
  •