title: How to find the maximum and minimum value in array
body: <p>Hi so I'm new at java programming and i'm currently at learning array. So what i'm trying to do is find the maximum and minimum value of an array but for some reason i cant find the minimum value but i can find the maximum value. </p>
  
  <p>Here is my output: </p>
  
  <pre><code>Enter the number of elements: 5                                                                                                               
  Enter a number: 1                                                                                                                             
  Enter a number: 2                                                                                                                             
  Enter a number: 3                                                                                                                             
  Enter a number: 4                                                                                                                             
  Enter a number: 5                                                                                                                             
  The maximum number is:5
  The minimum number is: 0
  </code></pre>
  
  <p>I've used the same statement for getting the max value by only changing the operator. But somehow the output is always zero.</p>
  
  <p>Here is my code: </p>
  
  <pre><code>import java.util.Scanner;
  
  public class Main
  {
      public static void main(String[] args) {
  
  
  
          Scanner input = new Scanner(System.in);
          System.out.print("Enter the number of elements: ");
          int elements = input.nextInt();
  
          int [] array = new int[elements];
          int max = array[0];
          int min = array[0];
  
          for(int i = 0; i&lt;elements; i++){
  
              System.out.print("Enter a number: ");
              array[i] = input.nextInt();
  
              if(array[i]&gt;max){
                  max = array[i];
  
              }
              if(array[i]&lt;min){
                  min = array[i];
              }
  
          }
  
          System.out.print("The maximum number is:" + max);
          System.out.println();
          System.out.print("The minimum number is: " + min);
  
  
  
  
  
  
      }
  }
  </code></pre>
  
  <p>Any help would be appreciated thanks!</p>