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: the codes.. needed the errors the points and i want to play again.. how should i do..?

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

    Default the codes.. needed the errors the points and i want to play again.. how should i do..?

    import java.util.Random;
    import java.util.Scanner;

    public class John {

    public static void main(String[] args) {

    System.out.println("Welcome to guessing game!");

    Random rand = new Random();
    int numberToGuess = rand.nextInt(10);
    int numberOfTries = 0;
    Scanner input = new Scanner(System.in);

    int guess;
    int Round;
    int target;
    int points;
    char play;
    int error;
    do{
    Round=1;
    points=0;
    error=0;

    while (Round<=3){
    target = rand.nextInt(9) + 1;
    System.out.println("please enter a number betwwen 1 to 10");
    guess = input.nextInt(10);
    numberOfTries++;

    if (guess == numberToGuess){
    System.out.println("you win!");
    System.out.println("the number was " +numberToGuess);
    points=points+100;
    }
    else if(guess < numberToGuess){
    System.out.println("your guess is too low");
    error=error+0;
    }
    else if (guess > numberToGuess){
    System.out.println("your guess is too high");

    }
    Round=Round+1;
    }
    System.out.println("your points");
    System.out.println("you have"+""+points+""+"pts.");
    System.out.println("you commited"+error+""+ "errors");
    System.out.println("It took you " + numberOfTries + " tries");
    System.out.println("Game over");
    System.out.print("do you want to play again?:");
    play=input.next().charAt(0);
    }while(play=='Y'||play=='y');

    System.out.println("Thank you!");
    }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: the codes.. needed the errors the points and i want to play again.. how should i do..?

    When posting code, please use the highlight tags to preserve formatting.

    What does this code do? Do you receive a compiler error? A run-time error? Something else? What's your question?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 1
    Last Post: November 6th, 2013, 02:48 AM
  2. software can discover the errors of java codes ?
    By websit in forum What's Wrong With My Code?
    Replies: 14
    Last Post: November 1st, 2011, 08:34 PM
  3. getting errors needed to be clear
    By erinbasim in forum Enterprise JavaBeans
    Replies: 1
    Last Post: February 4th, 2010, 03:24 AM
  4. Urgent Help needed with java codes
    By makarov in forum Java Theory & Questions
    Replies: 0
    Last Post: November 13th, 2009, 07:23 AM