A: In general, no. If you're using a huge nested if/else with ten branches or something, you probably aren't solving the problem the way we intended. Some large if/elses are better implemented with a loop, such as a cumulative sum.
When you do need an if/else that enumerates many cases, you should use logical operators to reduce and condense any redundant conditions into one larger conditional. For example:
if (x == 1) {
System.out.println("X is 1 or 3 or 5");
} else if (x == 3) {
System.out.println("X is 1 or 3 or 5");
} else if (x == 5) {
System.out.println("X is 1 or 3 or 5");
} else if (x == 4) {
System.out.println("X is 4");
} else {
System.out.println("X is not 1, 3, 4, or 5");
}
This turns into:
if (x == 1 || x == 3 || x == 5) {
System.out.println("X is 1 or 3 or 5");
} else if (x == 4) {
System.out.println("X is 4");
} else {
System.out.println("X is not 1, 3, 4, or 5");
}
For more in-depth examples, consult the textbook or lecture slides.