mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-05-05 06:18:32 +00:00
Merge pull request #1931 from hopesenddreams/patch-3
Improved int division comment and code
This commit is contained in:
commit
af1a21f47d
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user