will not walk through array
Could someone please look at this little snippet of code and tell me why I am not getting the correct value for x? I know that it is placing values in the array because array[index] is being added to numberM...however in the for loop near the bottom x is -1. Can someone please help? thanks. Just so you know I have an arraylist also because they are easier to print but i cant get them to work with floats.
/import java.util.ArrayList;
import java.util.Scanner;
publicclass MeanAndStandardDeviation{
publicstaticvoid main(String []args)
{
ArrayList list =new ArrayList();
float [] array =newfloat[49];
Scanner scan =new Scanner(System.in);
float number = 0;
float numberM =0;
float mean = 0;
float sd=0;
float sum1 =0;
float length=0;
float x=0;
float y=0;
float z=0;
int index=0;
float count =0;
System.out.println("Input a list of no more than fifty numbers.");
System.out.println("The program will then compute the standard deviation and the mean");
System.out.println("When finished with your list, enter -1");
array[index]= scan.nextFloat();
while(array[index] != -1)
//number = scan.nextFloat();
//number = index;
{
if(array[index]>0)
list.add(array[index]);
count = count +1;
numberM = numberM+ array[index];
System.out.println("Another?");
array[index]= scan.nextFloat();
}
for (int i=0;i<count;i++)
{
mean = numberM/count;
x = array[i];
y = x-mean;
sum1 = (float)Math.pow(y,2);
z = sum1/(count-1);
sd = (float)Math.sqrt(z);
}
System.out.println(list);
System.out.println();
System.out.println("");
System.out.println("mean is"+numberM+" divided by count "+count+" is "+mean);
System.out.println("x is"+x);
System.out.println("y is"+y);
System.out.println("z is"+z);
System.out.println("z is"+z);
System.out.println("sd is "+sd);
}
}
>

