Last active
December 21, 2015 14:23
-
-
Save cobratbq/c54ae053d68e9384c44c to your computer and use it in GitHub Desktop.
Example 2: Object with statically defined requirement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package thirdcomponent; | |
import java.math.BigDecimal; | |
import java.math.MathContext; | |
public class UtilWithStatics { | |
// Predefined math context for use in calculation. | |
private final static MathContext C = MathContext.DECIMAL32; | |
public static void main(String[] args) { | |
System.out.println(calculate(BigDecimal.ONE, | |
BigDecimal.valueOf(3L))); | |
// prints 0.3333333 | |
} | |
public static BigDecimal calculate(BigDecimal x, | |
BigDecimal y) { | |
return x.divide(y, C); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment