Ok, I am trying to set this program up using a for loop. I do not know if I am just to tired to find what is wrong, or if I am way off base, but my program is not compiling. Here is my code.
public static void main (String [] args)
{
int i;
int number = 0, sum = 0, numamount=0;
Scanner input = new Scanner(System.in);
{
System.out.println("Enter a number that is positive or zero(negative to terminate): ");
i = input.nextInt();
for(i>=0){
numamount++;
sum += i;
double average = sum/numamount;
}
}
{
System.out.println("You have entered " + numamount + " numbers");
System.out.println("Total of the numbers you entered is " + sum);
System.out.println("Average of the numbers is " + average);
}
}
}
I am trying to prompt the user to enter any number 0 or greater. Once a negative number is entered, it is supposed to give the number of integers given, as well as the sum and average of the given integers.


LinkBack URL
About LinkBacks
Reply With Quote