jeudi 19 novembre 2015

java error: double cannot be dereferenced

ok so i need to generate 7 random numbers between 1 and 100 and have the max be printed on the screen. however, when i compile this code:

public class ArrayofTemperatures
{
   public static void main(String[] args)
   {

      double [] temp = new double [7];
      int index;
      double max;
      double random = Math.random() * 100 + 1;

      temp[0] = random.nextDouble();
      max = temp[0];
      for (index = 1; index < temp.length; index++)
      {
         temp[index] = random.nextDouble();
         if (temp[index] > max)
            max = temp[index];

      }

      System.out.println("The highest score is: " + max);
   }
}

i get these two errors:

ArrayofTemperatures.java:12: error: double cannot be dereferenced temp[0] = random.nextDouble();

ArrayofTemperatures.java:16: error: double cannot be dereferenced temp[index] = random.nextDouble();




Aucun commentaire:

Enregistrer un commentaire