Advertisement
RederickDeathwill

Calculate to Gabriela

Sep 11th, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         // Example given: 3 to 10.
  7.         int min = 3;
  8.         int max = 10;
  9.         Integer result = sum(min, max);
  10.         System.out.println("The result is: " + result);
  11.     }
  12.    
  13.     public static Integer sum(int min, int max) {
  14.         ArrayList<Integer> intArray = new ArrayList();
  15.         for (Integer i = min+1; i < max; i++) {
  16.             intArray.add(i);
  17.         }
  18.         Integer sum = 0;
  19.         for (Integer j : intArray) {
  20.             sum = sum + j;
  21.         }
  22.         return sum;
  23.     }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement