title: Tidying code and fixing errors (java)
body: <p>I need to modify the code so that,</p>
  
  <ul>
  <li>its structure is better</li>
  <li>it is more readable</li>
  <li>it uses methods and parameters</li>
  <li>only one statement needs to be changed if a different number of integers is to be input</li>
  </ul>
  
  <p>My new code is at the bottom but it's not working yet, can't quite figure out what else I need to do to it. If anyone could help that would be fab.</p>
  
  <h3>Original Code</h3>
  
  <pre><code>import java.util.Scanner;
  
  public class MakeMeBetter
  {
      public static void main(String[] args)
      {
          int[] a = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
          Scanner b = new Scanner(System.in);
  
          System.out.println("Please input 10 numbers in the range 1-19 :&gt; ");
          int c = b.nextInt();
          while (c &lt; 1 || c &gt; 19)
          {
              System.out.println("Not in the range 1-19, please try again :&gt; ");
          }
          a[0] = c;
  
          int d = b.nextInt();
          while (d &lt; 1 || d &gt; 19)
          {
              System.out.println("Not in the range 1-19, please try again :&gt; ");
          }
          a[1] = d;
  
          int e = b.nextInt();
          while (e &lt; 1 || e &gt; 19)
          {
              System.out.println("Not in the range 1-19, please try again :&gt; ");
          }
          a[2] = e;
  
          int f = b.nextInt();
          while (f &lt; 1 || f &gt; 19)
          {
              System.out.println("Not in the range 1-19, please try again :&gt; ");
          }
          a[3] = f;
  
          int g = b.nextInt();
          while (g &lt; 1 || g &gt; 19)
          {
              System.out.println("Not in the range 1-19, please try again :&gt; ");
          }
          a[4] = g;
  
          int h = b.nextInt();
          while (h &lt; 1 || h &gt; 19)
          {
              System.out.println("Not in the range 1-19, please try again :&gt; ");
          }
          a[5] = h;
  
          int i = b.nextInt();
          while (i &lt; 1 || i &gt; 19)
          {
              System.out.println("Not in the range 1-19, please try again :&gt; ");
          }
          a[6] = i;
  
          int j = b.nextInt();
          while (j &lt; 1 || j &gt; 19)
          {
              System.out.println("Not in the range 1-19, please try again :&gt; ");
          }
          a[7] = j;
  
          int k = b.nextInt();
          while (k &lt; 1 || k &gt; 19)
          {
              System.out.println("Not in the range 1-19, please try again :&gt; ");
          }
          a[8] = k;
  
          int l = b.nextInt();
          while (l &lt; 1 || l &gt; 19)
          {
              System.out.println("Not in the range 1-19, please try again :&gt; ");
          }
          a[9] = l;
  
          System.out.println("\nArray contents");
          System.out.print((a[0] &lt; 10 ? " " : "") + a[0] + "  ");
          System.out.print((a[1] &lt; 10 ? " " : "") + a[1] + "  ");
          System.out.print((a[2] &lt; 10 ? " " : "") + a[2] + "  ");
          System.out.print((a[3] &lt; 10 ? " " : "") + a[3] + "  ");
          System.out.print((a[4] &lt; 10 ? " " : "") + a[4] + "  ");
          System.out.print((a[5] &lt; 10 ? " " : "") + a[5] + "  ");
          System.out.print((a[6] &lt; 10 ? " " : "") + a[6] + "  ");
          System.out.print((a[7] &lt; 10 ? " " : "") + a[7] + "  ");
          System.out.print((a[8] &lt; 10 ? " " : "") + a[8] + "  ");
          System.out.print((a[9] &lt; 10 ? " " : "") + a[9] + "  ");
          System.out.println();
  
          boolean noSwap = false;
          int startAt = 0;
          int stopAt = 9;
          while (startAt &lt; stopAt &amp;&amp; noSwap == false)
          {
              noSwap = true;
              for (int m=startAt; m&lt;stopAt; m++)
              {
                  if (a[m] &gt; a[m+1])
                  {
                      int t = a[m];
                      a[m] = a[m+1];
                      a[m+1] = t;
                      noSwap = false;
                  }
              }
              stopAt = stopAt - 1;
          }
  
          System.out.println("\nArray contents");
          System.out.print((a[0] &lt; 10 ? " " : "") + a[0] + "  ");
          System.out.print((a[1] &lt; 10 ? " " : "") + a[1] + "  ");
          System.out.print((a[2] &lt; 10 ? " " : "") + a[2] + "  ");
          System.out.print((a[3] &lt; 10 ? " " : "") + a[3] + "  ");
          System.out.print((a[4] &lt; 10 ? " " : "") + a[4] + "  ");
          System.out.print((a[5] &lt; 10 ? " " : "") + a[5] + "  ");
          System.out.print((a[6] &lt; 10 ? " " : "") + a[6] + "  ");
          System.out.print((a[7] &lt; 10 ? " " : "") + a[7] + "  ");
          System.out.print((a[8] &lt; 10 ? " " : "") + a[8] + "  ");
          System.out.print((a[9] &lt; 10 ? " " : "") + a[9] + "  ");
          System.out.println();
  
          double n = (a[0] + a[1] + a[2] + a[3] +
                        a[4] + a[5] + a[6] + a[7] +
                        a[8] + a[9]) / 10;
  
          System.out.println("The minimum number is: " + a[0]);
          System.out.println("The maximum number is: " + a[9]);
          System.out.println("The average value is: " + n);
          System.out.println("The median is: " + a[4]);
      }
  }
  </code></pre>
  
  <h3>New Code</h3>
  
  <pre><code>import java.util.Scanner;
  import java.math.*;
  public class MakeMeBetterImproved {
  
      public static void main(String[] args) {
          Scanner kybd = new Scanner(System.in);
          int[] numbers = new int[10];
          int array = 0;
  
          System.out.println("Enter 10 integers: ");
          for (int i = 0; i &lt; numbers.length; i++)  {
              numbers[i] = kybd.nextInt();
              int MyIntArray = array + i;
  
          }            
  
          System.out.println("The minimum number is: " + math.min);
          System.out.println("The maximum number is: " + math.max);
          System.out.println("The average value is: " + math.average);
          System.out.println("The median is: " + math.median);
      }
  }
  </code></pre>