(Dangling-else Problem) Determine the output for each of the given sets of code when x is 9 and y is 11 and when x is 11 and y is 9. Note that the compiler ignores the indentation in a Java program. Also, the Java compiler always associates an else with the immediately preceding if unless told to do otherwise by the placement of braces ({}). On first glance, the programmer may not be sure which if a particular else matches—this situation is referred to as the “dangling-else problem.” We’ve eliminated the indentation from the following code to make the problem more challenging. [Hint: Apply the indentation conventions you’ve learned.]
a) if (x<10)
if (y > 10)
System.out.println(“*****”);
else
System.out.println(“#####”);
System.out.println(“$$$$$”);
b) if (x < 10)
{
if (y > 10)
System.out.println(“*****”);
}
else
{
System.out.println(“#####”);
System.out.println(“$$$$$”);
}
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.