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 6 of 6

Thread: Java - eclipse (HiLo guessing game)

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java - eclipse (HiLo guessing game)

    Hi, I am having a hard time determining what the problem is with my codes. I have started over multiple times and I am getting at least 12 error messages. I am a beginner so this appears to be difficult. My assignment is to design & implement an application that plays the Hi-Lo guessing game with numbers (between 1 & 100) then repeatedly prompt the user to guess the number. I have used an online template to get what I have and this is what I have so far...
    [code=Java]
    import java.util.Scanner;
    import java.util.Random;

    public class HiLoGuess {

    public static void main(String[] args) {
    // TODO Auto-generated method stub

    }
    Scanner input = new Scanner(System.in);
    Random rand = new Random();
    int number = rand.nextInt(100) + 1;
    int guess;
    private Scanner scan;


    System.out.println("Guess a number between 1 and 100");


    guess = scan.nextInt();

    while (guess < number) {
    System.out.println("Higher!");
    guess = scan.nextInt();
    }
    while (guess > number) {
    System.out.println("Lower!");
    guess = scan.nextInt();
    }
    while (guess == number) {
    System.out.println("Correct!");
    break;
    }
    }
    }




    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java - eclipse (HiLo guessing game)

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    getting at least 12 error messages
    Please copy the full text and paste it here
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Java - eclipse (HiLo guessing game)

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

  4. #4
    Junior Member
    Join Date
    Jun 2014
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java - eclipse (HiLo guessing game)

    I got rid of your private scanner and replaced all guess = scan.nextInt(); with guess = input.nextInt();
    and it works fine..

    Code removed ********
    Last edited by Norm; June 28th, 2014 at 05:03 PM. Reason: Please don't do OPs work for him

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java - eclipse (HiLo guessing game)

    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Jun 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java - eclipse (HiLo guessing game)

    Quote Originally Posted by jakeburns View Post
    I got rid of your private scanner and replaced all guess = scan.nextInt(); with guess = input.nextInt();
    and it works fine..

    Code removed ********
    Thanks!

Similar Threads

  1. HiLo game in java
    By indytroll in forum What's Wrong With My Code?
    Replies: 6
    Last Post: April 28th, 2014, 09:13 AM
  2. Java Server Guessing Game
    By unijaw in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 16th, 2012, 11:29 AM
  3. JAVA Guessing Game Problem
    By adnan.alvee in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 24th, 2012, 12:02 AM
  4. Java Newbie..need help in guessing game program
    By confupavan in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 16th, 2011, 09:22 AM
  5. JAVA HIGH LOW NUMBER GUESSING GAME
    By Laxman2809 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: September 12th, 2011, 10:50 AM