SHARE
TWEET

Untitled

a guest Feb 27th, 2020 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  public static void main(String[] args) {
  2.         Scanner s = new Scanner (System.in);
  3.        
  4.         int[] array = new int[10];
  5.        
  6.         for (int i=0; i<array.length; i++) {
  7.             System.out.print("Number " + (i+1) + ": ");
  8.             array[i] = s.nextInt();
  9.         }
  10.        
  11.         System.out.println("Min: " + findMin(array));
  12.         System.out.println("Max: " + findMax(array));
  13.         System.out.println("Average: " + calculateAverage(array));
  14.     }
  15.    
  16.     public static int findMin(int[] array) {
  17.          int min = array[0];
  18.        
  19.         for (int i=0; i<array.length; i++) {
  20.             if (array[i]<min) {
  21.                 min = array[i];
  22.             }
  23.         }
  24.         return min;
  25.        
  26.     }
  27.    
  28.     public static int findMax(int[] array)  {
  29.          int max = array[0];
  30.        
  31.         for (int i=0; i<array.length; i++) {
  32.             if (array[i]>max) {
  33.                 max = array[i];
  34.             }
  35.         }
  36.         return max;
  37.     }
  38.    
  39.    
  40.     public static double calculateAverage(int[] array) {
  41.         int sum = 0;
  42.        
  43.         for (int i=0; i<array.length; i++) {
  44.             sum += array[i];
  45.         }
  46.        
  47.         return (double)sum / array.length;
  48.     }
  49.    
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top