|
i really need help
hey, this is my first post on this forum. I'll get right to the point. I'm creating a program that does a bunch of math operations such as Law of Cosines, Quadratic Formula, etc. I'm working on an tool that computes the Average of a specified amount of numbers given by the user. What i have so far, is an integer array that contains the number of numbers that the user can choose. I've also constructed a new integer array for the actual numbers. Now I'm trying to use a for loop in order for it to display "What is number 1?", "What is number 2?", etc. It prints that with no problem, but when i try to get it to have the values inputted and averaged, what it's doing is just dividing the last inputted number. This is all very unclear so take a look at the code:
Scanner scan = new Scanner(System.in);
System.out.print("How many numbers? ");
int x = scan.nextInt(); //numofnums
int[] numOfNums = {2, 3, 4, 5, 6, 7, 8, 9};
int z = numOfNums[x-2]; //index of array
int average = 0;
for(int y = 1; y < (z+1); y++)
{
System.out.print("What is number " + y + "? ");
Scanner scan2 = new Scanner(System.in);
int[] nums = new int[8];
average = scan2.nextInt() / x;
}
System.out.println(average);
-------------------
Can someone please help me figure out how to make it so that the numbers the user inputs are taken into account and averaged.
Last edited by gibsonrocker800 : 11-14-2007 at 04:30 AM.
|