fork download
  1. import java.util.*;
  2.  
  3. public class Main {
  4.  
  5. static int bruteForceSum(int[] nums, int l, int r) {
  6. int sum = 0;
  7. for (int i = l; i <= r; ++i) {
  8. sum += nums[i];
  9. }
  10. return sum;
  11. }
  12.  
  13. public static void main(String[] args) {
  14. int[] nums = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  15.  
  16. int l = 3, r = 7; // Example range [l, r]
  17. System.out.println("Brute Force Sum: " + bruteForceSum(nums, l, r));
  18. }
  19. }
Success #stdin #stdout 0.14s 55572KB
stdin
Standard input is empty
stdout
Brute Force Sum: 25