For the attention of first years really, I can’t stress enough the importance of studying carefully those first few lectures you had in SE15. A worrying number of people are still not aware of the mathematical implications of dividing two integers, and how things get rounded when you do. This is causing a lot of problems with the first coursework.

For those reluctant to crack open your folders of lecture notes, here is a few pointers:

int valueA = 1;

int valueB = 2;

System.out.println( valueA / valueB );

This will give an answer of zero. This is because the answer must be an integer due to dividing an integer by an integer, and integers must be exact whole numbers, so in this case it will be 0 rather than 1 as the result gets rounded down by default.

float valueA = 1;

float valueB = 2;

System.out.println( valueA / valueB );

This gives you more what you would expect if you did the calculation by hand, 0.5 This is because you have specified both values to be floating point numbers and so the answer will be as well. For some input values (I’ve picked simple examples) you will get a lot of zeros after the decimal place. To rectify this you will want to check out string formatting in the java documentation.

There are many other litte mathematical quirks like this with Java, but that one in particular should help with the first coursework. Please do re-read over your early lectures though as this kind of thing will come up time and time again and it always helps to be sure of yourself.