Nick-O-Rama

ArrayOperations

Mar 25th, 2015
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.36 KB | None | 0 0
  1.  
  2. public class ArrayOperations {
  3.    
  4.     public static int getTotal(int[] arr)
  5.     {
  6.         int total = 0;
  7.         for (int value: arr)
  8.             total += value;
  9.         return total;
  10.     }
  11.     public static double getTotal(double[] arr)
  12.     {
  13.         double total = 0;
  14.         for (double value: arr)
  15.             total += value;
  16.         return total;
  17.     }
  18.     public static float getTotal(float[] arr)
  19.     {
  20.         float total = 0;
  21.         for (float value: arr)
  22.             total += value;
  23.         return total;
  24.     }
  25.     public static long getTotal(long[] arr)
  26.     {
  27.         long total = 0;
  28.         for (long value: arr)
  29.             total += value;
  30.         return total;
  31.     }
  32.    
  33.    
  34.     public static double getAverage(int[] arr)
  35.     {
  36.         return getTotal(arr) / (double)arr.length;
  37.     }
  38.     public static double getAverage(double[] arr)
  39.     {
  40.         return getTotal(arr) / (double)arr.length;
  41.     }
  42.     public static double getAverage(float[] arr)
  43.     {
  44.         return getTotal(arr) / (double)arr.length;
  45.     }
  46.     public static double getAverage(long[] arr)
  47.     {
  48.         return getTotal(arr) / (double)arr.length;
  49.     }
  50.    
  51.  
  52.     public static int getHighest(int[] arr)
  53.     {
  54.         int highest = arr[0];
  55.         for (int value: arr)
  56.         {
  57.             if (value > highest)
  58.                 highest = value;
  59.         }
  60.         return highest;
  61.     }
  62.     public static double getHighest(double[] arr)
  63.     {
  64.         double highest = arr[0];
  65.         for (double value: arr)
  66.         {
  67.             if (value > highest)
  68.                 highest = value;
  69.         }
  70.         return highest;
  71.     }
  72.     public static float getHighest(float[] arr)
  73.     {
  74.         float highest = arr[0];
  75.         for (float value: arr)
  76.         {
  77.             if (value > highest)
  78.                 highest = value;
  79.         }
  80.         return highest;
  81.     }
  82.     public static long getHighest(long[] arr)
  83.     {
  84.         long highest = arr[0];
  85.         for (long value: arr)
  86.         {
  87.             if (value > highest)
  88.                 highest = value;
  89.         }
  90.         return highest;
  91.     }
  92.    
  93.  
  94.     public static int getLowest(int[] arr)
  95.     {
  96.         int lowest = arr[0];
  97.         for (int value: arr)
  98.         {
  99.             if (value < lowest)
  100.                 lowest = value;
  101.         }
  102.         return lowest;
  103.     }
  104.     public static double getLowest(double[] arr)
  105.     {
  106.         double lowest = arr[0];
  107.         for (double value: arr)
  108.         {
  109.             if (value < lowest)
  110.                 lowest = value;
  111.         }
  112.         return lowest;
  113.     }
  114.     public static float getLowest(float[] arr)
  115.     {
  116.         float lowest = arr[0];
  117.         for (float value: arr)
  118.         {
  119.             if (value < lowest)
  120.                 lowest = value;
  121.         }
  122.         return lowest;
  123.     }
  124.     public static long getLowest(long[] arr)
  125.     {
  126.         long lowest = arr[0];
  127.         for (long value: arr)
  128.         {
  129.             if (value < lowest)
  130.                 lowest = value;
  131.         }
  132.         return lowest;
  133.     }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment