A comment on style: most professional programmers would prefer that you not comment every line of code. If it's obvious what is going on (like in your println statements) you shouldn't add a comment. The comments about the division are probably fine, for example, since the code can be cryptic by itself.
Of course, if your teacher wants you to comment every line, by all means do it.
Thanks for your advice! Once I'm done with learning exercises, I will definitely do as you describe; but until I am confident that I will remember what System.out.println means, I will comment it as a study aid. My instructor does prefer more comments over less as a general rule.
Along those lines, once you do remember what those are for, try to focus your comments osn why you are doing something rather than just what you are doing. Nothing is worse that reading code like this:
// add x and y to get the total total = (x*y) + z;
Something changed -- it probably used to be just x+y -- but now the comments are out of date and likely worse than no comments at all.
Comments 7
So if I inputed 99,999,999,999,999 or 7.777.777.777 or 5,555,555,555.555?
Reply
Reply
Reply
Of course, if your teacher wants you to comment every line, by all means do it.
Reply
Reply
// add x and y to get the total
total = (x*y) + z;
Something changed -- it probably used to be just x+y -- but now the comments are out of date and likely worse than no comments at all.
Reply
Reply
Leave a comment