I am trying to create an array of 20 values the have 4 methods that 1st will create a total of all values listed, 2nd search the array and return all values less than 5.00, 3rd return the average of the values using the output method from the first method and finally display the average of all values in the array greater than the average. I am getting an error that total + prices is not a valid statement. Here is my code:
public class Prices
{
public static void main (String[] args)
{
double[] prices = {1.59,8.98,2.56,7.82,9.70,2.85,
1.98,10.80,5.05,12.76,13.20,7.36,4.86,1.25,2.05,2.70,
9.98,4.25,13.05,6.00};
double average;
double total = 0.0;
int i;
for (i = 0; i < 20; i++)
{
total + prices;
}
System.out.println("Sum of all prices: "+total+"\n" );
for (i = 0; i < 20; i++)
{
if (prices < 5.00){
System.out.println(prices + " is less than $5.00");
}
}
average = total / (20);
System.out.println("\nThe average price is " + average + "\n");
for (i = 0; i < 20; i++)
{
if (prices > average) {
System.out.println(prices + " is greater than the average");
}
}
}
}
Any help is greatly appreciated