Merge pull request #1931 from hopesenddreams/patch-3

Improved int division comment and code
This commit is contained in:
Adam Bard 2015-10-31 18:17:42 +08:00
commit af1a21f47d

View File

@ -207,8 +207,8 @@ public class LearnJava {
System.out.println("1+2 = " + (i1 + i2)); // => 3
System.out.println("2-1 = " + (i2 - i1)); // => 1
System.out.println("2*1 = " + (i2 * i1)); // => 2
System.out.println("1/2 = " + (i1 / i2)); // => 0 (0.5 truncated down)
System.out.println("1/2 = " + (i1 / (i2*1.0))); // => 0.5
System.out.println("1/2 = " + (i1 / i2)); // => 0 (int/int returns an int)
System.out.println("1/2 = " + (i1 / (double)i2)); // => 0.5
// Modulo
System.out.println("11%3 = "+(11 % 3)); // => 2
@ -416,7 +416,7 @@ public class LearnJava {
// easier way, by using something that is called Double Brace
// Initialization.
private static final Set<String> COUNTRIES = HashSet<String>() {{
private static final Set<String> COUNTRIES = new HashSet<String>() {{
add("DENMARK");
add("SWEDEN");
add("FINLAND");