1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-07-30 19:40:36 +02:00

Improve arithmetic output

This commit is contained in:
Andrew Gallasch
2017-10-30 23:58:22 +10:30
committed by GitHub
parent ab34af7c2d
commit 833c7bea6c

View File

@@ -312,7 +312,7 @@ public class LearnJava {
System.out.println("2-1 = " + (i2 - i1)); // => 1
System.out.println("2*1 = " + (i2 * i1)); // => 2
System.out.println("1/2 = " + (i1 / i2)); // => 0 (int/int returns int)
System.out.println("1/2 = " + (i1 / (double)i2)); // => 0.5
System.out.println("1/2.0 = " + (i1 / (double)i2)); // => 0.5
// Modulo
System.out.println("11%3 = "+(11 % 3)); // => 2