Quiz submission error

I am receiving this error when I submit my code for the quiz on lesson 5: You have 1 more lines of unexecuted code than the solution, which is more than the limit of 0.

I wanted to know if anyone could give me some insight on what the problem with my code is given this feedback. Thanks

What that basically means is you have an extra line of code somewhere that is not being used, or is just unnecessary. I.e. you might have an extra if statement that is unneeded. I have a feeling it is an extra if statement, and if it is, remember that we can have more than one conditional. We can use && for and, || for or.

3 Likes

Yup! @Dj_Figueiredo has you on the right track!

Here’s an example. Let’s say that we want to print “Larger” if a number is bigger than 10, “Large” if it’s bigger than 1, and “Small” otherwise. Here’s one way to do that:

int number = 8;
if (number > 10) {
  System.out.println("Larger");
} else if (number > 1) {
  System.out.println("Large");
} else if (number <= 1) {
  System.out.println("Small");
} else {
  System.out.println("Small");
}

If you examine this code, it will work, and it does solve the problem. But, the final line of code that prints “Small” will never be executed! Why? Because any number that is not bigger than 1 is therefore less than or equal to 1, and so we’ll never enter that final else block.

I suspect that this is what our grader is looking at. By using the line number you should be able to pinpoint what line of code is never executing and eliminate it.

Note that this can also happen if you have a complex conditional and one part is never being used. Similar to the example above:

int number = 8;
if (number > 10) {
  System.out.println("Larger");
} else if (number > 1) {
  System.out.println("Large");
} else if (number <= 1 || number <= 0) {
  System.out.println("Small");
}

Again, this code works—but it works the same if we remove that number <= 0. Because, if a number is less than or equal to 1, then it must be less than or equal to zero as well, and so the right side of the || is never used.

Hopefully this helps! Feel free to post more details if you’re still stuck.

4 Likes