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

Thread: please help me to fix my code ,this code for bulls and cows game ,(i linked the errors in the massege)

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    My Mood
    Angry
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default please help me to fix my code ,this code for bulls and cows game ,(i linked the errors in the massege)

    void play()
    {

    int j=0;
    Result test=new Result();
    int [] arr = new int[4];
    Game player1=new Game();
    Game player2=new Game();
    Random rand = new Random();
    int n = rand.nextInt(5040) + 1;
    Scanner input=new Scanner(System.in);

    j++;
    Choice come=new Choice(array1[n].arr);
    while(j>0)
    {
    System.out.printf("enter your guesss:");



    [COLOR="#FF0000"]
    for(int i=0 ;i<4;i++)
    {

    arr[i]=input.nextInt();


    }[/red]





    come.testChoice(arr, test);
    if(test.Bulls==4)
    {
    System.out.printf("you guesses the number you have win\n");
    break;
    }

    System.out.printf("your scored %d balls and %d cows",test.Bulls,test.kiliot);
    player1.filter(arr,test.Bulls,test.kiliot);
    if(player2.makeAChoice()==1)
    {
    System.out.printf("computer win tha game\n");
    break;
    }
    j++;
    }
    input.close();


    }

    }



    i run mu code and show me these errors :
    enter your guesss:1 2 3 4
    your scored 0 balls and 1 cows
    My guess is :
    2 6 7 8
    Enter Bulls:

    1
    Enter Kliots:
    2
    enter your guesss:Exception in thread "main" java.util.NoSuchElementException
    at java.util.Scanner.throwFor(Unknown Source)
    at java.util.Scanner.next(Unknown Source)
    at java.util.Scanner.nextInt(Unknown Source)
    at java.util.Scanner.nextInt(Unknown Source)
    at Game.play(Game.java:130)
    at Game.main(Game.java:51)


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

    Default Re: please help me to fix my code ,this code for bulls and cows game ,and i run it and their show me errors???

    What is your question?

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    My Mood
    Angry
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help me to fix my code ,this code for bulls and cows game ,(i linked the errors in the massege)

    i upteded it

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: please help me to fix my code ,this code for bulls and cows game ,(i linked the errors in the massege)

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

    enter your guesss:Exception in thread "main" java.util.NoSuchElementException
    at java.util.Scanner.throwFor(Unknown Source)
    at java.util.Scanner.next(Unknown Source)
    at java.util.Scanner.nextInt(Unknown Source)
    at java.util.Scanner.nextInt(Unknown Source)
    at Game.play(Game.java:130)
    At line 130 the code called the nextInt() method when there was not anything to read.
    Make sure there is data to be read before trying to read it. For example the hasNextInt() will say if there is a number ready to be read. Or change the code or input file so the reads that are done matches the data in the file.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Cow and Bulls Game Help (Urgent)
    By Cyclone in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 27th, 2013, 10:55 AM
  2. Getting Exception Errors, But Not Sure How To Fix Code
    By noel222 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 3rd, 2012, 12:09 PM
  3. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM
  4. How to fix this code?
    By ice in forum AWT / Java Swing
    Replies: 26
    Last Post: November 29th, 2010, 07:10 PM