title: I have error in arrayindexoutofbounds and I've looked up many places and not been able to spot the mistake
body: <pre><code>Main Class:
  public class Main {
  
    private static String [] Countries={"UK", "Italy",
              "Germany", "Thailand","Denmark"};
    static double average[] = new double[5];
    double[] results = new double[5];
  
    public static String getWinner(ArrayList&lt;MissUniverse&gt;alist){
      int champion = 0;
      for (int s = 0; s &lt; alist.size(); s++){
          if (alist.get(s).average() &gt; alist.get(0).average() ) {
              winner= s;
          }
      }
      return alist.get(winner).getCountry();
    }
  
  public static String firstRunnerUp(ArrayList&lt;MissUniverse&gt;alist){
      int firstrunnerUp =0;
      for (int s = 0; s &lt; alist.size(); s++){
          if (alist.get(s).average() &gt; alist.get(0).average() &amp;&amp; alist.get(s).getCountry() != getWinner(alist) ) {
              firstrunnerUp = s;
          }
      }
      return alist.get(firstrunnerUp).getCountry();
  
    }
  
   public static void main (String[] args){
     ArrayList&lt;MissUniverse&gt; alist = new ArrayList&lt;MissUniverse&gt;();
   MissUniverse missUniverse[] = new MissUniverse[Countries.length];
  
          for(int i=0;i&lt;Countries.length;i++)
          {
              missUniverse[i] = new MissUniverse(Countries[i]);
              missUniverse[i].getScore();
              alist.add(missUniverse[i]);
          }
  
  
     System.out.printf("%-15s%-5s%-5s%-5s%-5s%-5s%-10s",
                  "Countries","1","2","3","4","5","Average");
      System.out.println();
      for (int i = 0; i &lt; Countries.length; i++){
      System.out.print(Countries[i]);
      System.out.print("    ");
      missUniverse[i].printInfo();
      System.out.printf("%5.1f", alist.get(i).average() );  ///this line 
      System.out.println();
      }
      System.out.println("The result is");
      System.out.println("Winner: Miss " + getWinner(alist) );
      System.out.println("1st Runner Up: Miss " + firstRunnerUp(alist) );
  
    }
  }
  
  </code></pre>
  
  <p>MissUniverse class:</p>
  
  <pre><code>class MissUniverse { 
    public static int SIZE=5;
    private String country;
    private double[] score;  
  
    public MissUniverse(String country){
      this.country = country;
      score = new double [SIZE];
    }
  
    public String getCountry(){
      return country;
    }
  
    public void getScore(){
        for (int i=0;i&lt;score.length;i++)
          {
              score[i] = Math.random()*10;
          }
    }
  
    public void setCountry(String newCountry) {
      this.country = newCountry;
    }
  
   private int highest(){
    int i;
          double highest;
          highest = score[0];
  
          for (i = 0; i &lt;score.length; i++)
          {
              if (highest &lt; score [i])
              {
                  highest = score[i] ;
              }
          }
          return i;
    }
  
    private int lowest(){      
    int i;
          double lowest;
          lowest = score[0];
          for (i = 0; i &lt;score.length; i++)
          {
              if (lowest &gt; score [i])
              {
                  lowest = score[i];
              }
          }
          return i;  
    }
  
    public double average(){
  
      double sum = 0.0;
       for (int i = 0; i &lt; score.length; i++){
          sum +=  score[i];
       }
      double average;
      average = (sum - score[lowest()] - score[highest()] )/ score.length -2;
    }
  
    public void printInfo(){
  
        for(int i=0;i&lt; score.length;i++){  
        System.out.printf("%-5.1f",score[i]);
        }
  
    }
  }
  </code></pre>
  
  <p>The error: </p>
  
  <pre><code>Countries      1    2    3    4    5    Average   
  UK    3.3  5.8  6.6  4.8  0.2  Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
      at MissUniverse.average(Main.java:121)
      at Main.main(Main.java:50)
  
  </code></pre>
  
  <p>I think the problem is in the average() or lowest() or highest() methods but I cant find the bug. I dont think there is anything wrong in those methods that can lead to counting outside the array length (length is 8) and index is 0-7. I've looked at other links in stackoverflow but I can't find whats wrong. I hope someone can help me?</p>
  
  <p>The output I am trying to achieve is:</p>
  
  <pre><code>Countries       1    2    3    4    5   Average   
  UK             6.2  2.5  9.7  4.3  0.1  3.4
  Italy          7.1  1.2  1.6  5.5  1.9  3.7
  Germany        8.5  3.3  6.7  4.0  6.0  5.9
  Thailand       5.3  8.5  1.5 10.0  2.7  4.1
  Denmark        3.1  4.9  5.4  0.8  3.2  3.4
  
  
  The result is:
  Winner: Miss Germany
  1st runner up: Miss Thailand
  </code></pre>