From de138a4a925c8019cdacc10cb2ecce2ea58f3c53 Mon Sep 17 00:00:00 2001 From: iaforek Date: Tue, 13 Jun 2017 22:29:27 +0100 Subject: [PATCH] BAEL-837 - Couple of smaller changes --- .../maths/FloatingPointArithmetic.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/core-java/src/main/java/com/baeldung/maths/FloatingPointArithmetic.java b/core-java/src/main/java/com/baeldung/maths/FloatingPointArithmetic.java index 9cdeeb5e81..4163adcf09 100644 --- a/core-java/src/main/java/com/baeldung/maths/FloatingPointArithmetic.java +++ b/core-java/src/main/java/com/baeldung/maths/FloatingPointArithmetic.java @@ -13,30 +13,37 @@ public class FloatingPointArithmetic { System.out.println("b = " + b); System.out.println("c = " + c); - double ab = a + b; - System.out.println("a + b = " + ab); + double sum_ab = a + b; + System.out.println("a + b = " + sum_ab); double abc = a + b + c; System.out.println("a + b + c = " + abc); - double ac = a + c; - System.out.println("a + c = " + ac); + double ab_c = sum_ab + c; + System.out.println("ab + c = " + ab_c); + + double sum_ac = a + c; + System.out.println("a + c = " + sum_ac); double acb = a + c + b; System.out.println("a + c + b = " + acb); - double ac_b = ac + b; + double ac_b = sum_ac + b; System.out.println("ac + b = " + ac_b); + double ab = 18.1; + double ac = 34.67; + double sum_ab_c = ab + c; + double sum_ac_b = ac + b; + System.out.println("ab + c = " + sum_ab_c); + System.out.println("ac + b = " + sum_ac_b); + BigDecimal d = new BigDecimal(String.valueOf(a)); BigDecimal e = new BigDecimal(String.valueOf(b)); BigDecimal f = new BigDecimal(String.valueOf(c)); - BigDecimal def; - BigDecimal dfe; - - def = d.add(e).add(f); - dfe = d.add(f).add(e); + BigDecimal def = d.add(e).add(f); + BigDecimal dfe = d.add(f).add(e); System.out.println("d + e + f = " + def); System.out.println("d + f + e = " + dfe);