1
0

Kgv.java 683 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import java.math.BigDecimal;
  2. /*
  3. * To change this template, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. /**
  7. *
  8. * @author LH
  9. */
  10. public class Kgv
  11. {
  12. public static void main(String[] args) throws Exception
  13. {
  14. }
  15. public static BigDecimal calculateKGV(BigDecimal x, BigDecimal y)
  16. {
  17. return x.multiply(y).divide(calculateGGT(x, y));
  18. }
  19. public static BigDecimal calculateGGT(BigDecimal x, BigDecimal y)
  20. {
  21. if(y.intValue()==0)//nullercheck
  22. {
  23. return x;
  24. }
  25. return calculateGGT(y, x.remainder(y));
  26. }
  27. }