Blocks
A block is a group of one or more statements enclosed in braces. A block begins with an opening brace ({
) and ends with a closing brace (}
). Between the opening and closing braces, you can code one or more statements. For example:
{
int i, j;
i = 100;
j = 200;
}
if ( i > 0)
{
String s = “The value of i is “ + i;
System.out.print(s);
}
The other style is to place the opening brace for the block on the same line as the statement that the block is associated with:
if ( i > 0) {
String s = “The value of i is “ + i;
System.out.print(s);
}