Java Reference
In-Depth Information
gradeLetter = 'B';
System.out.println("You did very well on this test.");
}
else
if (testMark >= 70)
{
gradeLetter = 'C';
System.out.println("Not bad, but you need to study more
for future tests.");
}
else
if (testMark >= 60)
{
gradeLetter = 'D';
System.out.println("Your test result suggests that you
need a tutor.");
else
{
gradeLetter = 'F';
System.out.println("Your test result is pathetic; you
need summer school.");
}
DANGLING-ELSE PROBLEM
Whenifandif-elseareusedtogether,andthesourcecodeisnotproperlyindented,it
can be difficult to determine which if associates with the else. For example:
if (car.door.isOpen())
if (car.key.isPresent())
car.start();
else car.door.open();
Didthedeveloperintendfortheelsetomatchtheinnerif,butimproperlyformatted
the code to make it appear otherwise? For example:
if (car.door.isOpen())
if (car.key.isPresent())
car.start();
Search WWH ::




Custom Search