February 2014
Beginner
1248 pages
62h 25m
English
After the calculation has been performed, line 25
System.out.printf("Sum is %d%n", sum); // display sum
uses method System.out.printf to display the sum. The format specifier %d is a placeholder for an int value (in this case the value of sum)—the letter d stands for “decimal integer.” The remaining characters in the format string are all fixed text. So, method printf displays "Sum is ", followed by the value of sum (in the position of the %d format specifier) and a newline.
Calculations can also be performed inside printf statements. We could have combined the statements at lines 23 and 25 into the statement
System.out.printf("Sum is ...
Read now
Unlock full access