Simple Array Sum

Sort by

recency

|

3432 Discussions

|

  • + 0 comments

    Language: JAVA 15

    We can solve this problem in two ways:

    1) By using For Each Loop to iterate all elements in List and adding it to the variable sum :

    public static int simpleArraySum(List<Integer> ar) {
        
        int sum= 0;
        for( int i : ar ){
            sum = sum + i ;   // i contains elements of List ar
        }
    		
        return sum;
        }
    

    2) And by using For Loop where we will add each element present in List using ListName.get(index) method to variable sum :

    public static int simpleArraySum(List<Integer> ar) {
        
        int sum= 0;
        for( int i=0; i < ar.size(); i++ ){
            sum = sum + ar.get(i) ;
        }
        
        return sum;
        }
    
  • + 0 comments

    how to find the test case1 and test case 2. Question is n't display.

  • + 0 comments

    return sum(ar)

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/b7KAvErmVIw

    int simpleArraySum(vector<int> ar) {
        int sum = 0;
        for(int i = 0; i < ar.size(); i++){
            sum += ar[i];
        }
        return sum;
    }
    
  • + 0 comments

    Costless Containers offers both 20' and 40' long units for rent, sale, or rent-to-own. These spacious containers are ideal for various storage needs, whether for personal use, business, or construction purposes 20' and 40' long units available. With secure, durable, and weather-resistant construction, they provide a reliable solution for storing equipment, inventory, or other valuable items. Available in different conditions, these units offer flexible rental terms, allowing you to choose the best option for your needs.