r/learnjava • • May 18 '16

Issue with a code on TMC. Some assistance would be welcome.

https://imgur.com/6fno9mi
1 Upvotes

4 comments sorted by

2

u/[deleted] May 19 '16

I don't know jack about Java, but from the error I would try to remove all "System.out.println" and only print out the sum of the ages. in this case.

System.out.println(a+b);

PS. do you have a picture of the sumOfTheAgesTest.java too?

1

u/i_like_outer_space May 19 '16

This seems correct. You only need to print what it asks for - no fluff. It's trying to assert that your output = the sum of ages.

Therefore 3 != "john and jerry are 3 years old in total"

2

u/bsungur May 19 '16 edited May 19 '16

No. The issue isn't in the result. It is in the way that the inputs are being handled.

Rather than reading input (reader.nextLine()), then outputting the question. Try printing the question THEN reading the input. Also making these changes should prevent you from printing what was inputted with the +s in the souts.

Edit: Basically the "other values" that the test is referring to are the names and ages that are printed immediately following each of your inputs.

Also: Alt+Shift+F

2

u/desrtfx May 19 '16

When doing the MOOC, you need to follow the input and output format exactly as presented.

That's basically what the error message "Assertion failed" tells you.