The value of the expression (x = x) is true.
The expression:
((x >= 5) && (y < 8)) || ((z == 6)
has the same value as the expression:
x >= 5 && y < 8 || z == 6
x && y > 6
If x and y are ints, the above is a valid boolean expression which states that x and y are both greater than 6.
Local variables may be declared within any pair of matching curly braces
{ and }.
In the if-else statement
if (x == 1)
{
if (y == 2)
System.out.println("CAMPUS ");
else
System.out.println("WORLD ");
}
else
{
System.out.println("SHOOT ");
System.out.println("WIDE");
}
the first set of curly brackets is essential to preserve the semantics (meaning) of the code.
In the if-else statement
if (x == 1)
{
if (y == 2)
System.out.println("CAMPUS ");
else
System.out.println("WORLD ");
}
else
{
System.out.println("SHOOT ");
System.out.println("WIDE");
}
the second set of curly brackets is essential to preserve the semantics (meaning) of the code.
The following program fragment contains no errors.
if (x == 1)
{
int z = 4;
System.out.println("Hello ");
}
else
{
z = 3;
System.out.println("Goodbye");
{
The following program fragment contains no errors.
public class test
{
public static int z = 8; // Note class variable
public static void main(String[] args)
{
if (z == 8)
{
int z = 4;
System.out.println("z has the value " + z);
}
else
{
z = 3;
System.out.println("z has the value " + z);
}
}
}