473,498 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help with brakets

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

Expand|Select|Wrap|Line Numbers
  1. package mooredMod2;
  2.  
  3.  
  4. import java.util.Scanner;
  5. import java.util.Random;
  6. import java.util.*;
  7. import java.io.*;
  8.  
  9. public class GuessingGame {
  10.  
  11.  
  12. public static void main(String[] args) {
  13.     {
  14.  
  15.     BufferedReader keyboard = new BufferedReader (new InputStreamReader (System.in)); 
  16.         Scanner scan = new Scanner(System.in);
  17.  
  18.  
  19.          boolean more = true; 
  20.  
  21.         Random generator = new Random();
  22.         while (true)
  23.         {
  24.  
  25.  
  26.             String input ; 
  27.  
  28.             int numGuesses = 0; 
  29.  
  30.  
  31.  
  32.             boolean correct = false; 
  33.  
  34.  
  35.  
  36.             int theirGuess ; 
  37.  
  38.  
  39.  
  40.  
  41.             int value; 
  42.              value = generator.nextInt(10) + 1;
  43.              System.out.println ( + value );
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.              System.out.println("Guess a number between 1 and 10");
  51.  
  52.             while (value < 10 )    // a loop from chapter 5 
  53.             {
  54.                                 numGuesses  += 1 ;
  55.  
  56.  
  57.  
  58.  
  59.  
  60.                 theirGuess = scan.nextInt ();
  61.  
  62.  
  63.                 if(theirGuess<value)
  64.                 {
  65.                     System.out.println("Too low!");
  66.  
  67.                 }
  68.  
  69.                 else if (theirGuess>value)
  70.                 {
  71.                     System.out.println("Too high!");
  72.  
  73.                 }
  74.  
  75.  
  76.         if (value == theirGuess)
  77.         {
  78.  
  79.                 System.out.println("You are correct! "  );    
  80.         }
  81.  
  82.  
  83.         else 
  84.         {
  85.             System.out.println(" You are incorrect guess again! ");
  86.  
  87.  
  88.         }
  89.  
  90.          if (theirGuess == value)
  91.  
  92.         {
  93.             System.out.println("This is how many guesses it took you " + numGuesses  );
  94.  
  95.  
  96.         }            
  97.  
  98.  
  99.          scan.nextLine();
  100.  
  101.  
  102.          if (theirGuess == value)
  103.          {
  104.  
  105.              System.out.println("Would you like to play again? (Eneter true or false)");
  106.              input = keyboard.readLine();
  107.          }
  108.          while(input.equals("Yes"));
  109.          if(input.equals("No"));
  110.          System.exit(0);
  111.  
  112.  
  113.             }
  114.  
  115.  
  116.         }
  117.         }
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.      }//end of main method
  129.  
  130.  
  131.  
  132. }
  133. }
  134. }
Sep 23 '08 #1
6 1388
Ganon11
3,652 Recognized Expert Specialist
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.
Sep 24 '08 #2
Nepomuk
3,112 Recognized Expert Specialist
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)
Sep 24 '08 #3
cdm2883
53 New Member
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
Sep 24 '08 #4
cdm2883
53 New Member
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.NullPointerException
at mooredMod2.GuessingGame.main(GuessingGame.java:84)

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

Thanks
Sep 24 '08 #5
Nepomuk
3,112 Recognized Expert Specialist
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 NullPointerException means, that in line 84 there's a variable, which wasn't declared yet. For example, the code
Expand|Select|Wrap|Line Numbers
  1. public class Test {
  2.     public static void main(String[] args) {
  3.         String myWord;
  4.         System.out.println(myWord);
  5.     }
  6. }
would throw a NullPointerException, because it knows there IS something called myWord, but it doesn't have a value yet.

Greetings,
Nepomuk
Sep 24 '08 #6
JosAH
11,448 Recognized Expert MVP
For example, the code
Expand|Select|Wrap|Line Numbers
  1. public class Test {
  2.     public static void main(String[] args) {
  3.         String myWord;
  4.         System.out.println(myWord);
  5.     }
  6. }
would throw a NullPointerException, 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
NullPointerException is thrown because a PrintStream duly prints "null" when
a null value is passed to its print() method.

kind regards,

Jos
Sep 25 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

21
6482
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
6
4298
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
3316
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
5340
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
2
1923
by: MyNameIsnt | last post by:
Can anyone tell me why, when I click on the buttons it register 2 characters on the display? if you use the right mousebutton it works ok, but the buttons dont flash?? it works fine without the...
6
2208
by: James Brown [MVP] | last post by:
Hi, I am having trouble understanding how the 'const' modifier affects the 'left-right' rule when deciphering c-declarations: const int *x; // x is a pointer to a 'const int' int const *x; ...
2
2355
by: Alex Maghen | last post by:
This is a bit of an abuse of this group. Just a nit, but I'm hoping someone really good with Regular Expressions can help me out here. I need to write a regular expression that will do the...
6
1353
by: fatima.issawi | last post by:
Hello, Are brakets () allowed in a file path? eg. Passing: Y:\trak\pdf\98-00_2_123\tst.ps works but
3
1599
by: wuzertheloser | last post by:
The correct program should look like this: Total number of voting cards: 55 Votes for candidate 1: 1 Votes for candidate 2: 10 Votes for candidate 3: 8 Votes for candidate 4: 13 Votes...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4908
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.