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);

}

}

>

[3647 byte] By [pberardi1a] at [2007-11-27 11:53:22]
# 1

if(array[index]>0)

list.add(array[index]);

count = count +1;

numberM = numberM+ array[index];

System.out.println("Another?");

array[index]= scan.nextFloat();

Before we look at your logic, lets clear one thing up. Which of the above lines of code should be inside your if statement. Since you have no braces { } around it only the list.add() line is in the if statement.

floundera at 2007-7-29 18:49:53 > top of Java-index,Java Essentials,New To Java...
# 2

yep you are right flounder... but i ran it again and the mean still works out. I know that the array has those correct values in it because of the numberM= numberM + array[index] ; however when it comes to the for loop...array or x starts with the value -1.0 I need it to be the value of the first location in the array.

pberardi1a at 2007-7-29 18:49:53 > top of Java-index,Java Essentials,New To Java...
# 3

Try incrementing index in the while loop.

pbrockway2a at 2007-7-29 18:49:53 > top of Java-index,Java Essentials,New To Java...