fork(1) download
  1. public class Main {
  2.  
  3. public static void main(String[] args) {
  4. System.out.println(lcmofarray(new int[] { 1, 2, 3, 4, 5 }, 0, 5));
  5. }
  6.  
  7. public static int lcmofarray(int[] arr, int start, int end) {
  8. if ((end - start) == 1)
  9. return lcm(arr[start], arr[end - 1]);
  10. else
  11. return (lcm(arr[start], lcmofarray(arr, start + 1, end)));
  12. }
  13.  
  14. public static int lcm(int a, int b) {
  15. int num1, num2;
  16. if (a > b) {
  17. num1 = a;
  18. num2 = b;
  19. } else {
  20. num1 = b;
  21. num2 = a;
  22. }
  23. for (int i = 1; i <= num2; i++) {
  24. if ((num1 * i) % num2 == 0) {
  25. return i * num1;
  26. }
  27. }
  28. return -1;
  29. }
  30. }
Success #stdin #stdout 0.06s 381248KB
stdin
Standard input is empty
stdout
60