Food for thought #47 (Computer Applications/Computer Science)

Which of the following code snippets correctly rounds a floating-point variable n to the nearest integer and stores the rounded integer value back into n?

a) n = (int)(n + 0.5f);
b) n = n > 0 ? (int)(n + 0.5f) : (int)(n - 0.5f);
c) System.out.printf("%.0f", n);
d) n = Math.round(n + 0.5f);