Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2012
    Location
    NYC
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Brackets in Java coding

    Are there any basic rules in Java programming for the placement of brackets?
    I have coded, only to be told error messages that lead me across lines of code, just for me to find out it was the brackets. SO, is there any type of way to safely place brackets?

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,722
    Thanks
    41
    Thanked 191 Times in 190 Posts
    braces {} or brackets []?

    brackets are used to declare an array (or point out the index of an array
    example of brackets
    Code:
    int[] numArray = new int[5];
    numArray[0] = 1;
    numArray[1] = 7;
    curly braces are used to chunk off sections of code as well as classes and namespaces...
    example of curly braces:
    Code:
    private class demo
    {
      ......
    }
    
    if(...)
    {
       .....
    }
    
    else
    {
       .....
    }
    
    for(.....)
    {
       .....
    }
    etc...

    You can also have both in one line, the declaration of an array and then initialization...
    example:
    Code:
    int[] numbers = new int[7] { 4, 7, 2, 1, 3, 3, 0 };
    Judging from your other posts, I think it would behoove you to do some intro to Java lessons. There are some here as well as additional resources in this thread. A little bit of google can go a long way.
    Last edited by alykins; 07-26-2012 at 06:52 PM.

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •