Advertisement
fosterbl

ListTotal.java

Jan 8th, 2020
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. //(c) A+ Computer Science
  2. //www.apluscompsci.com
  3. //Name -
  4. //Date -
  5.  
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. import java.util.Arrays;
  9.  
  10. public class ListTotal{
  11.  
  12.    //Complete this method to total all elements in list
  13.    //Although it says List instead of ArrayList, just pretend it is an arraylist for now
  14.    public static int total( List<Integer> list ){
  15.       return 0;
  16.    }
  17.    
  18.    /*Expected Output
  19.  
  20.    12301
  21.    -44
  22.    -11568
  23.    32767
  24.    510
  25.    476
  26.    497
  27.    -35
  28.    -947
  29.    1089
  30.    -99
  31.    6011
  32.    
  33.    */
  34.    
  35.    //DO NOT TOUCH MAIN - it is set up for testing. The expected output is above
  36.    public static void main( String args[] ){
  37.       System.out.println( total( Arrays.asList(-99,1,2,3,4,5,6,7,8,9,10,12345) ) );
  38.       System.out.println( total( Arrays.asList(10,9,8,7,6,5,4,3,2,1,-99)));
  39.       System.out.println( total( Arrays.asList(10,20,30,40,50,-11818,40,30,20,10)));
  40.       System.out.println( total( Arrays.asList(32767)));
  41.       System.out.println( total( Arrays.asList(255,255)));
  42.       System.out.println( total( Arrays.asList(9,10,-88,100,-555,1000)));
  43.       System.out.println( total( Arrays.asList(10,10,10,11,456)));
  44.       System.out.println( total( Arrays.asList(-111,1,2,3,9,11,20,30)));
  45.       System.out.println( total( Arrays.asList(9,8,7,6,5,4,3,2,0,-2,-989)));
  46.       System.out.println( total( Arrays.asList(12,15,18,21,23,1000)));
  47.       System.out.println( total( Arrays.asList(250,19,17,15,13,11,10,9,6,3,2,1,-455)));
  48.       System.out.println( total( Arrays.asList(9,10,-8,10000,-5000,1000)));                                    
  49.    }
  50.    
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement