I'm working on a program where I need to have the user enter the size of the array and then enter the numbers to be stored in the array. If the user enters in -99999 the program quit. I also need to display the sum of numbers enter into the array and the average of the numbers. Later on I need to display all of the values enter into the array, but not right now. I can get the sum and average and the size of the array, but I'm having trouble getting the values to be stored into the array. I would appreciate any help.
Sincerely yours;
jdm
package hw3;
//Libraries
import javax.swing.*;
import java.util.*;
//Declairng class
public class Main {
//declaring main with arguments
public static void main(String[] args) {
double Average,
sum,
difference,
temp;
sum = 0.0;
Average = 0.0;
difference = 0.0;
temp = 0.0;
int size = 0;
double myArray[ ] = new double[size];
int a = 0;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the size of the array: ");
size = scanner.nextInt();
System.out.println("Size = " + size);
System.out.print("Enter numbers: ");
temp = scanner.nextDouble();
a++;
for (int i = a; i < size; i++)
{
if (i == size)
break;
else if (temp == -99999.0)
break;
myArray[i] = temp;
System.out.println("temp = " + temp);
sum += temp;
System.out.print("Enter numbers: ");
temp = scanner.nextDouble();
System.out.println("i = " + i);
// myArray[i] = temp;
}
if (sum <= 0){
sum = sum + temp;
sum = sum + -99999.0;
}
else if (sum >= 0){
sum = sum + temp;}
System.out.println("The sum: " + sum);
Average = sum / size;
System.out.println("The Average is: " + Average);
//System.out.format( "Average Rainfall:%5.2f\n\n", Average );
// for (int i = 0; i < size; i++) {
// System.out.println("array: " + myArray[size]);
//difference between the monthly and annual averages
//difference = Math.abs( myArray[i] - Average );
//System.out.format("%15.2f\n", difference);
// }
}
}