Hot answers tagged

4

I'd maybe suggest an exercise of splitting these kinds of statements up into multiple variables and lines of code. So take this line: if ((n+"").length() == (((n+1)+"").length())) { And come up with this code: String nString = n + ""; int nLength = stringN.length(); int nPlusOne = n+1; String nPlusOneString = nPlusOne + ""; int nPlusOneLength = ...


4

I suspect that you handle such situations by informally building the parse tree of the expression in your mind. Maybe not all at once, but a bit at a time, perhaps. I'm not a cognition expert, of course, but it might help him if you teach him to do it explicitly on paper. He needs a table of operator precedence, of course and needs to be able to deal with ...


3

I think the student's problem is not with types, but first with the parsing of complex expressions (not to be confused with the tracing of it's evaluation). Mentally building the abstract syntax tree from the linear text representation. First rewrite remove the extra parentheses at right, and introduce a line break if ( (n+"").length() == ((n+1)+""...


1

You say “when he is finished, he no longer fully understands them.” There is a good practice to write self documenting code. This is done not with comments, but with well named entities (methods, classes, objects). This helps you to see what the code does (I do not mean how it does it, but in turn it will help you understand how it works). Therefore teach ...


Only top voted, non community-wiki answers of a minimum length are eligible