Java: evenSum method takes too long to execute in edge cases, how can I optimize the loop?
I am working on a Java method called evenSum that sums all even numbers between two integers, from and to, inclusive. The requirements specify that if from is greater than to, the method should return -1. For example, evenSum(4, 6) should return 10, evenSum(10, 15) should return 36, and evenSum(4, 4) should return 4.