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?

07-26-2012, 07:48 PM

alykins

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.