# ulvis.paste.net

Paste Search Dynamic
Recent pastes
sum of array is
1. import java.util.Arrays;
2.
3.   class Main {
4.
5.     public static void main (string args[]){
6.        int numbers[]= {1,5,-9,12,-3,89, 18,23,4,-6};
7.
8.        // Find minimum (lowest) value in array using loop
9.        system.out.println("Minimum Value = " + getMinValue(numbers));
10.
11.       // Find maximum (largest) value in array using loop
12.        system.out.println("Maximum Value = " + getMaxValue(numbers));
13.
14.       // Determine the average of all element values in array using loop
15.          system.out.println("Average Value = " + getAvgValue(numbers));
16.
17.       // ADD CODE TO SORT THE NUMBERS IN THE ARRAY, PRINT THE SORTED ARRAY
18.         arrays.sort(numbers);
19.         system.out.println("Sorted Array: " + arrays.toString(numbers));
20.        system.out.println("The median value in array is: " + getMedValue(numbers));
21.
22.     }
23.
24.     // find the median value in the array
25.
26.     public static float getMedValue(int[] numbers){
27.         int med1=numbers[4];
28.         int med2=numbers[5];
29.         float med3=0.00f;
30.     try{
31.
32.         {
33.        med3=((med2+med1)/2F);
34.         }
35.     }
36.     catch (arithmeticexception msg) {
37.                 system.out.println ("Error: " + msg);
38.         }catch (arrayindexoutofboundsexception msg) {
39.                 system.out.println ("Error: " + msg);
40.         }
41.     return med3;
42.     }
43.     //Find maximum (largest) value in array using loop
44.     public static int getMaxValue(int[] numbers){
45.         int maxValue = numbers[0];
46.         for (int i=0; i<numbers.length; i++){
47.                 if (maxValue<numbers[i])
48.                 maxValue=numbers[i];
49.         }
50.
51.        return maxValue;
52.     }
53.
54.     //Find minimum (lowest) value in array using loop
55.     public static int getMinValue(int[] numbers){
56.         int minValue = numbers[0];
57.
58.          for (int i=0; i<numbers.length; i++){
59.                 if (minValue>numbers[i])
60.                 minValue=numbers[i];
61.          }
62.
63.         return minValue;
64.     }
65.
66.     //Find the average of an array of integers
67.     public static float getAvgValue(int[] numbers){
68.
69.
70. float arrSum=0.00f;
71. float arrAve=0.00f;
72. for(int i=0;i<numbers.length; i++){
73.         arrSum=arrSum+numbers[i];
74. }
75.  system.out.println("The total sum of array is: " + (arrSum));
76.  arrAve=(arrSum/numbers.length);
77.
78.        return arrAve;
79.     }
80.
81. }  // Main
82.
83.
Parsed in 0.051 seconds