title: Why am I not getting the minimum value in an array JAVA?
body: <pre><code>import java.util.*;
  public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      System.out.print(&quot;Enter the size ??&quot;);
      int n = sc.nextInt();
      int[] marks = new int[n + 1];
      
      for (int i = 0; i &lt; n; i++) {
          System.out.println(&quot;Enter &quot; + i + &quot; number ??&quot;);
          marks[i] = sc.nextInt();
      }
      
      System.out.println(&quot;The  following numbers are : &quot;);
      for (int j = 0; j &lt; marks.length - 1; j++) {
          System.out.println(marks[j] + &quot; &quot;);
      }
      
      int max = marks[0];
      int min = marks[0];
      int s = marks.length;
      for (int i = 0; i &lt; s; i++) {
          if (marks[i] &gt; max) {
              max = marks[i];
          }
          if (marks[i] &lt; min) {
              min = marks[i];
          }
      }
      
      System.out.println(&quot;Max is &quot; + max + &quot; Min is &quot; + min);
  }
  </code></pre>
  <p>Output:</p>
  <pre><code>Enter the size ??2
  Enter 0 number ??
  56
  Enter 1 number ??
  56
  The  following numbers are : 
  56 
  56 
  Max is 56 Min is 0
  </code></pre>