having trouble using for while loop
this is what im supposed to do:
Write a program that will read an unspecified number of positive numbers from the keyboard and determine the sum and the average of these numbers. A negative number should be used to terminate the input, i.e. when the program encounters a negative number, it should stop prompting and reading data and at that point should output the results. Note that the negative number that terminates the looping should not be added to the sum and certainly should not be counted as one of the valid numbers.
A sample program run would look like this :
Enter a number that is positive or zero 3
Enter a number that is positive or zero 5
Enter a number that is positive or zero 6
Enter a number that is positive or zero 4
Enter a number that is positive or zero -1
You have entered 4 numbers
Total of the numbers you entered is 18
Average of the numbers is 4.5
The program should use a For WHILE loop to accomplish it's mission.
here is my code and i dont think its anywhere close to right
import java.util.Scanner ;
public class Assign7_1_Roberts{
public static void main (String [] args){
//Create Scanner
Scanner input = new Scanner(System.in);
i = initialValue;
int number = 0, i = 0; sum = 0, numamount = 0; // You can change the variable names.
for(i = 0; i < 100; i++)
while(i < endValue1)
{ // Begin while statement
System.out.println("Enter a number that is positive or zero: "); // Get the next number
String userInput = input.nextLine();
sum = sum+number; // Get the sum so far.
numamount++; // Get the number amount so far.
} // End while statement.
double average = sum/numamount; //Get the average.
System.out.println("You have entered " + numamount + " numbers"); // Output amount of numbers
System.out.println("Total of the numbers you entered is " + sum); // Output sum of numbers
System.out.println("Average of the numbers is " + average); // Output average of numbers.
}
}