help with brakets

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cdm2883
    New Member
    • Sep 2007
    • 53

    help with brakets

    here is my code, i am having trouble with getting my brakets in the right place so i can run my program.

    [code=java]
    package mooredMod2;


    import java.util.Scann er;
    import java.util.Rando m;
    import java.util.*;
    import java.io.*;

    public class GuessingGame {


    public static void main(String[] args) {
    {

    BufferedReader keyboard = new BufferedReader (new InputStreamRead er (System.in));
    Scanner scan = new Scanner(System. in);


    boolean more = true;

    Random generator = new Random();
    while (true)
    {


    String input ;

    int numGuesses = 0;



    boolean correct = false;



    int theirGuess ;




    int value;
    value = generator.nextI nt(10) + 1;
    System.out.prin tln ( + value );






    System.out.prin tln("Guess a number between 1 and 10");

    while (value < 10 ) // a loop from chapter 5
    {
    numGuesses += 1 ;





    theirGuess = scan.nextInt ();


    if(theirGuess<v alue)
    {
    System.out.prin tln("Too low!");

    }

    else if (theirGuess>val ue)
    {
    System.out.prin tln("Too high!");

    }


    if (value == theirGuess)
    {

    System.out.prin tln("You are correct! " );
    }


    else
    {
    System.out.prin tln(" You are incorrect guess again! ");


    }

    if (theirGuess == value)

    {
    System.out.prin tln("This is how many guesses it took you " + numGuesses );


    }


    scan.nextLine() ;


    if (theirGuess == value)
    {

    System.out.prin tln("Would you like to play again? (Eneter true or false)");
    input = keyboard.readLi ne();
    }
    while(input.equ als("Yes"));
    if(input.equals ("No"));
    System.exit(0);


    }


    }
    }










    }//end of main method



    }
    }
    }[/code]
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    We are not here to be a programming equivalent of the 'spellchecker'. Put your code into Notepad and indent it properly, and you will be able to see where extra/missing brackets are. Or, let a program do it for you - get an IDE like BlueJ or Eclipse, or even a text formatting editor like Notepad++, put your code in there, and use the bracket highlighting to find your errors, but don't make us do it in our spare time because you're too lazy.

    Comment

    • Nepomuk
      Recognized Expert Specialist
      • Aug 2007
      • 3111

      #3
      Listen, I've told you before: Use the [CODE] ... [/CODE] tags, when posting code! I'm giving you another warning: Use them! If you don't start using them now, consequences will follow soon.

      Greetings,
      Nepomuk (Moderator)

      Comment

      • cdm2883
        New Member
        • Sep 2007
        • 53

        #4
        Originally posted by Nepomuk
        Listen, I've told you before: Use the [CODE] ... [/CODE] tags, when posting code! I'm giving you another warning: Use them! If you don't start using them now, consequences will follow soon.

        Greetings,
        Nepomuk (Moderator)

        What do you mean use the [CODE] ... [/CODE] tags

        Comment

        • cdm2883
          New Member
          • Sep 2007
          • 53

          #5
          But any way i got the brackets fixed. Down at the bottom where i am askin for the user to put true or false. I still cant get that to work, It comes back with this..

          Exception in thread "main" java.lang.NullP ointerException
          at mooredMod2.Gues singGame.main(G uessingGame.jav a:84)

          Can any1 please explain to me what that means and why im getting that.

          Thanks

          Comment

          • Nepomuk
            Recognized Expert Specialist
            • Aug 2007
            • 3111

            #6
            Originally posted by cdm2883
            What do you mean use the [CODE] ... [/CODE] tags
            It means, either you write [CODE] before and [/CODE] after your code, or you click on the # button in the editing window. See the code earlier in this thread? It's in a codebox, which was created through the CODE tags.

            Anyway, glad to hear, you've solved the bracket problem. The NullPointerExce ption means, that in line 84 there's a variable, which wasn't declared yet. For example, the code [code=java]public class Test {
            public static void main(String[] args) {
            String myWord;
            System.out.prin tln(myWord);
            }
            }[/code] would throw a NullPointerExce ption, because it knows there IS something called myWord, but it doesn't have a value yet.

            Greetings,
            Nepomuk

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by Nepomuk
              For example, the code [code=java]public class Test {
              public static void main(String[] args) {
              String myWord;
              System.out.prin tln(myWord);
              }
              }[/code] would throw a NullPointerExce ption, because it knows there IS something called myWord, but it doesn't have a value yet.
              Local variables need to be initialized before they can be used. The above yields
              a compilation error. Even if you initialize that variable to null explicitly no
              NullPointerExce ption is thrown because a PrintStream duly prints "null" when
              a null value is passed to its print() method.

              kind regards,

              Jos

              Comment

              Working...